<p>Sending and getting requests to the <strong class="pkg">SCSCP</strong> server(s), the client operates with processes. Process is an abstraction which in other words may be also called a remote task. It encapsulates an input/output TCP stream (see <code class="func">IsInputOutputTCPStream</code> (<a href="chap3.html#X805BB9468642A787"><span class="RefLink">3.1-1</span></a>)) from the client to the server and the process ID of the CAS running as a server (deduced from the connection initiation message; may be unassigned, if the server CAS did not communicate it).</p>
<p>There are two ways to create processes. One of them is to specify the hostname and port where the <strong class="pkg">SCSCP</strong> server is running; in this case a new input/output TCP stream will be created. Another way is first to establish the connection with the <strong class="pkg">SCSCP</strong> server using <code class="func">NewSCSCPconnection</code> (<a href="chap6.html#X82AD581386371E0E"><span class="RefLink">6.1-2</span></a>) and then keep it alive across multiple remote procedure calls, thus saving time on the DNS lookup and connection initiation. This may give a good speedup in computations with an intensive message exchange. Note that as long as such connection is open, other <strong class="pkg">SCSCP</strong> clients will not be able to get through, so if several clients are interchanging with the <strong class="pkg">SCSCP</strong> server at the same time, they should not block each other with long-lasting connections.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsSCSCPconnection</code></td><td class="tdright">( filter )</td></tr></table></div>
<p>This is the category of <strong class="pkg">SCSCP</strong> connections. Objects in this category are created using the function <code class="func">NewSCSCPconnection</code> (<a href="chap6.html#X82AD581386371E0E"><span class="RefLink">6.1-2</span></a>).</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NewSCSCPconnection</code>( <var class="Arg">hostname</var>, <var class="Arg">port</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>For a string <var class="Arg">hostname</var> and an integer <var class="Arg">port</var>, creates an object in the category <code class="func">IsSCSCPconnection</code> (<a href="chap6.html#X7B7A635581A56B05"><span class="RefLink">6.1-1</span></a>). This object will encapsulate two objects: <code class="code">tcpstream</code>, which is the input/output TCP stream to <code class="code"><var class="Arg">hostname</var>:<var class="Arg">port</var></code>, and <code class="code">session_id</code>, which is the result of calling <code class="func">StartSCSCPsession</code> (<a href="chap4.html#X86D913277AFF2366"><span class="RefLink">4.1-1</span></a>) on <code class="code">tcpstream</code>. The connection will be kept alive across multiple remote procedure calls until it will be closed with <code class="func">CloseSCSCPconnection</code> (<a href="chap6.html#X7CFF508878D17C03"><span class="RefLink">6.1-3</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">SetInfoLevel( InfoSCSCP, 2 );</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">s:=NewSCSCPconnection("localhost",26133);</span>
#I Creating a socket ...
#I Connecting to a remote socket via TCP/IP ...
#I Got connection initiation message
#I <?scscp service_name="GAP" service_version="4.dev" service_id="localhost:2\
6133:52918" scscp_versions="1.0 1.1 1.2 1.3" ?>
#I Requesting version 1.3 from the server ...
#I Server confirmed version 1.3 to the client ...
< connection to localhost:26133 session_id=localhost:26133:52918 >
<span class="GAPprompt">gap></span> <span class="GAPinput">CloseSCSCPconnection(s);</span>
<p>Closes <strong class="pkg">SCSCP</strong> connection <var class="Arg">s</var>, which must be an object in the category <code class="func">IsSCSCPconnection</code> (<a href="chap6.html#X7B7A635581A56B05"><span class="RefLink">6.1-1</span></a>). Internally, it just calls <code class="func">CloseStream</code> (<a href="../../../doc/ref/chap10_mj.html#X786E5520803FDE00"><span class="RefLink">Reference: CloseStream</span></a>) on the underlying input/output TCP stream of <var class="Arg">s</var>.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsProcess</code></td><td class="tdright">( filter )</td></tr></table></div>
<p>This is the category of processes. Processes in this category are created using the function <code class="func">NewProcess</code> (<a href="chap6.html#X8712E82B811A4170"><span class="RefLink">6.2-2</span></a>).</p>
<p>In the first form, <var class="Arg">command</var> and <code class="code">server</code> are strings, <var class="Arg">listargs</var> is a list of <strong class="pkg">GAP</strong> objects and <code class="code">port</code> is an integer.</p>
<p>In the second form, an <strong class="pkg">SCSCP</strong> connection in the category <code class="func">NewSCSCPconnection</code> (<a href="chap6.html#X82AD581386371E0E"><span class="RefLink">6.1-2</span></a>) is used instead of <code class="code">server</code> and <code class="code">port</code>.</p>
<p>Calls the <strong class="pkg">SCSCP</strong> procedure with the name <var class="Arg">command</var> and the list of arguments <var class="Arg">listargs</var> at the server and port given by <var class="Arg">server</var> and <var class="Arg">port</var> or encapsulated in the <var class="Arg">connection</var>. Returns an object in the category <code class="code">IsProcess</code> for the subsequent waiting the result from its underlying stream.</p>
<p>It accepts the following options:</p>
<ul>
<li><p><code class="code">output:="object"</code> is used to specify that the server must return the actual object evaluated as a result of the procedure call. This is the default action requested by the client if the <code class="code">output</code> option is omitted.</p>
</li>
<li><p><code class="code">output:="cookie"</code> is used to specify that the result of the procedure call should be stored on the server, and the server should return a remote object (see <a href="chap6.html#X7C3B6B4C7A0666F8"><span class="RefLink">6.5</span></a> ) pointing to that result (that is, a cookie);</p>
</li>
<li><p><code class="code">output:="nothing"</code> is used to specify that the server is supposed to reply with a <code class="code">procedure_completed</code> message carrying no object just to signal that the call was completed successfully (for the compatibility, this will be evaluated to a <code class="code">"procedure completed"</code> string on the client's side);
</li>
<li><p><code class="code">cd:="cdname"</code> is used to specify that the <strong class="pkg">OpenMath</strong> symbol corresponding to the first argument <var class="Arg">command</var> should be looked up in the particular content dictionary <code class="code">cdname</code>. Otherwise, it will be looked for in the default content dictionary (<code class="code">scscp_transient_1</code> for the <strong class="pkg">GAP</strong> <strong class="pkg">SCSCP</strong> server);</p>
</li>
<li><p><code class="code">debuglevel:=N</code> is used to obtain additional information attributes together with the result. The <strong class="pkg">GAP</strong> <strong class="pkg">SCSCP</strong> server does the following: if <code class="code">N=1</code>, it will report about the CPU time in milliseconds required to compute the result; if <code class="code">N=2</code> it will additionally report about the amount of memory used by <strong class="pkg">GAP</strong> in bytes will be returned (using the output of <code class="func">MemoryUsageByGAPinKbytes</code> (<a href="chap9.html#X8312112E79686EF6"><span class="RefLink">9.3-4</span></a>) converted to bytes); if <code class="code">N=3</code> it will additionally report the amount of memory in bytes used by the resulting object and its subobjects (using the output of <code class="func">MemoryUsage</code> (<a href="../../../doc/ref/chap12_mj.html#X7F4D216B7DF7BE9D"><span class="RefLink">Reference: MemoryUsage</span></a>)).</p>
</li>
</ul>
<p>See <code class="func">CompleteProcess</code> (<a href="chap6.html#X796557D67A4CA868"><span class="RefLink">6.2-3</span></a>) and <code class="func">EvaluateBySCSCP</code> (<a href="chap6.html#X7C745B2878E0AC41"><span class="RefLink">6.3-1</span></a>) for examples.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CompleteProcess</code>( <var class="Arg">process</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: record with components <code class="code">object</code> and <code class="code">attributes</code></p>
<p>The function waits, if necessary, until the underlying stream of the process will contain some data, then reads the appropriate <strong class="pkg">OpenMath</strong> object from this stream and closes it.</p>
<p>It has the option <code class="code">output</code> which may have two values:</p>
<ul>
<li><p><code class="code">output:="cookie"</code> has the same meaning as for the <code class="func">NewProcess</code> (<a href="chap6.html#X8712E82B811A4170"><span class="RefLink">6.2-2</span></a>)</p>
</li>
<li><p><code class="code">output:="tree"</code> is used to specify that the result obtained from the server should be returned as an XML parsed tree without its evaluation.</p>
</li>
</ul>
<p>In the following example we demonstrate combination of the two previous functions to send request and get result, calling the procedure <code class="code">WS_Factorial</code>, installed in the previous chapter:</p>
<p>See more examples in the description of the function <code class="func">EvaluateBySCSCP</code> (<a href="chap6.html#X7C745B2878E0AC41"><span class="RefLink">6.3-1</span></a>), which combines the two previous functions by sending request and getting result in one call.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TerminateProcess</code>( <var class="Arg">process</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The function is supposed to send an <q>out-of-band</q> interrupt signal to the server. Current implementation works only when the server is running as <q>localhost</q> by sending a <code class="code">SIGINT</code> to the server using its PID contained in the <var class="Arg">process</var>. It will do nothing if the server is running remotely, as the <strong class="pkg">SCSCP</strong> specification allows the server to ignore interrupt messages. Remote interrupts will be introduced in one of the next versions of the package.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EvaluateBySCSCP</code>( <var class="Arg">command</var>, <var class="Arg">listargs</var>, <var class="Arg">server</var>, <var class="Arg">port</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EvaluateBySCSCP</code>( <var class="Arg">command</var>, <var class="Arg">listargs</var>, <var class="Arg">connection</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: record with components <code class="code">object</code> and <code class="code">attributes</code></p>
<p>In the first form, <var class="Arg">command</var> and <code class="code">server</code> are strings, <var class="Arg">listargs</var> is a list of <strong class="pkg">GAP</strong> objects and <code class="code">port</code> is an integer.</p>
<p>In the second form, an <strong class="pkg">SCSCP</strong> connection in the category <code class="func">NewSCSCPconnection</code> (<a href="chap6.html#X82AD581386371E0E"><span class="RefLink">6.1-2</span></a>) is used instead of <code class="code">server</code> and <code class="code">port</code>.</p>
<p>Calls the SCSCP procedure with the name <var class="Arg">command</var> and the list of arguments <var class="Arg">listargs</var> at the server and port given by <code class="code">server</code> and <code class="code">port</code> or encapsulated in the <var class="Arg">connection</var>.</p>
<p>Since <code class="func">EvaluateBySCSCP</code> combines <code class="func">NewProcess</code> (<a href="chap6.html#X8712E82B811A4170"><span class="RefLink">6.2-2</span></a>) and <code class="func">CompleteProcess</code> (<a href="chap6.html#X796557D67A4CA868"><span class="RefLink">6.2-3</span></a>), it accepts all options which may be used by that functions ( <code class="code">output</code>, <code class="code">cd</code> and <code class="code">debuglevel</code> ) with the same meanings.</p>
<p>which works exactly like <code class="func">IdGroup</code> (<a href="../../../pkg/smallgrp/doc/chap1_mj.html#X83044B9D7E3BDF35"><span class="RefLink">smallgrp: IdGroup</span></a>):</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">G:=DihedralGroup(64);</span>
<pc group of size 64 with 6 generators>
<span class="GAPprompt">gap></span> <span class="GAPinput">IdGroupWS(G);</span>
[ 64, 52 ]
<p>The <strong class="pkg">OpenMath</strong> package supports both binary and XML encodings for <strong class="pkg">OpenMath</strong>. To switch between them, use <code class="func">SwitchSCSCPmodeToBinary</code> and <code class="func">SwitchSCSCPmodeToXML</code>. When the package is loaded, the mode is initially set to XML. On the clients's side, you can change the mode back and forth as many times as you wish during the same SCSCP session. The server will autodetect the mode and will response in the same format, so one does not need to set the mode on the server's side.</p>
<p>For example, let us create a vector over <span class="SimpleMath">GF(3)</span>:</p>
<p>We call the <strong class="pkg">SCSCP</strong> procedure <code class="code">Identity</code> just to test how this object may be sent back and forth. The total length of the procedure call message is 969 symbols:</p>
<span class="GAPprompt">gap></span> <span class="GAPinput">SwitchSCSCPmodeToBinary();</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">EvaluateBySCSCP("Identity",[x],"localhost",26133);</span>
#I Creating a socket ...
#I Connecting to a remote socket via TCP/IP ...
#I Got connection initiation message
#I <?scscp service_name="GAP" service_version="4.dev" service_id="localhost:2\
6133:42448" scscp_versions="1.0 1.1 1.2 1.3" ?>
#I Requesting version 1.3 from the server ...
#I Server confirmed version 1.3 to the client ...
#I Composing procedure_call message:
3C3F7363736370207374617274203F3E0A18121408060773637363703163616C6C5F6964061E6C\
6F63616C686F73743A32363133333A34323434383A3256675A5562755A0806147363736370316F\
7074696F6E5F72657475726E5F6F626A6563740600151008060E73637363703170726F63656475\
72655F63616C6C1008110873637363705F7472616E7369656E745F314964656E74697479100805\
046C697374316C69737410080605617269746831706F7765721008091166696E6669656C643170\
72696D69746976655F656C656D656E7401031101001110080605617269746831706F7765721008\
091166696E6669656C64317072696D69746976655F656C656D656E740103110101111008060561\
726974683174696D65731008091166696E6669656C64317072696D69746976655F656C656D656E\
7401031101001111111113193C3F736373637020656E64203F3E0A
#I Total length 339 bytes
#I Request sent ...
#I Waiting for reply ...
#I <?scscp start ?>
#I Got back: object [ Z(3)^0, Z(3), 0*Z(3) ] with attributes
[ [ "call_id", "localhost:26133:42448:2VgZUbuZ" ] ]
rec( attributes := [ [ "call_id", "localhost:26133:42448:2VgZUbuZ" ] ], object := [ Z(3)^0, Z(3), 0*Z(3) ] )
<span class="GAPprompt">gap></span> <span class="GAPinput">SetInfoLevel(InfoSCSCP,3);</span>
</pre></div>
<p>As we can see, the size of the message is almost three times shorter, and this is not the limit. Switching to binary <strong class="pkg">OpenMath</strong> encoding in combination with pickling and unpickling from <strong class="pkg">IO</strong> package (see in the last Chapter) and special methods for pickling compressed vectors implemented in the <strong class="pkg">Cvec</strong> available in <strong class="pkg">GAP</strong> 4.5 allow to dramatically reduce the overhead for vectors and matrices over finite fields, making a roundtrip up to a thousand times faster.</p>
<p>The <strong class="pkg">SCSCP</strong> package introduces new kind of objects - <em>remote objects</em>. They provide an opportunity to manipulate with objects on remote services without their actual transmitting over the network. Remote objects store the information that allows to access the original object: the server name and the port number through which the object can be accessed, and the variable name under which it is stored in the remote system. Two remote objects are equal if and only if all these three parameters coincide.</p>
<p>There are two types of remote object which differ by their lifetime:</p>
<ul>
<li><p>temporary remote objects which exist only within a single session;</p>
</li>
<li><p>persistent remote objects which stay alive across multiple sessions.</p>
</li>
</ul>
<p>First we show the example of the temporary remote object in a session. The procedure <code class="code">PointImages</code> returns the set of images of a point <span class="SimpleMath">i</span> under the generators of the group <span class="SimpleMath">G</span>. First we create the symmetric group <span class="SimpleMath">S_3</span> on the client and store it remotely on the server (call 1), then we compute set of images for <span class="SimpleMath">i=1,2</span> (calls 2,3) and finally demonstrate that we may retrieve the group from the server (call 4):</p>
<p>After the stream is closed, it is no longer possible to retrieve the group <span class="SimpleMath">G</span> again or use it as an argument.</p>
<p>Thus, the usage of remote objects existing during a session reduces the network traffic, since we pass only references instead of actual <strong class="pkg">OpenMath</strong> representation of an object. Also, the remote object on the server may accumulate certain information in its properties and attributes, which may not be included in it default <strong class="pkg">OpenMath</strong> representation.</p>
<p>Now we show remote objects which remain alive after the session is closed. Such remote objects may be accessed later, for example, by:</p>
<ul>
<li><p>subsequent procedure calls from the same instance of <strong class="pkg">GAP</strong> or another system;</p>
</li>
<li><p>other instances of <strong class="pkg">GAP</strong> or another systems (if the identifier of an object is known)</p>
</li>
<li><p>another <strong class="pkg">SCSCP</strong> servers which obtained a reference to such object as an argument of a procedure call.</p>
<p>Returns the remote object corresponding to the object created at <var class="Arg">server</var><code class="code">:</code><var class="Arg">port</var> from the <strong class="pkg">OpenMath</strong> representation of the first argument <var class="Arg">obj</var>. The second form is just a synonym.</p>
<p>Internally, the remote object carries all the information which is required to get access to the original object: its identifier, server and port:</p>
<p>When the remote object is printed in the <strong class="pkg">OpenMath</strong> format, we use symbols <code class="code">@</code> and <code class="code">:</code> to combine these parameters in the <strong class="pkg">OpenMath</strong> reference:</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RemoteObjectsFamily</code></td><td class="tdright">( family )</td></tr></table></div>
<p>This is the family of remote objects.</p>
<p>This function retrieves the remote object from the remote service in the <strong class="pkg">OpenMath</strong> format and constructs it locally. Note, however, that for a complex mathematical object its default <strong class="pkg">OpenMath</strong> representation may not contain all information about it which was accumulated during its lifetime on the <strong class="pkg">SCSCP</strong> server.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ UnbindRemoteObject</code>( <var class="Arg">remoteobject</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: <code class="keyw">true</code> or <code class="keyw">false</code></p>
<p>Removes any value currently bound to the global variable determined by <var class="Arg">remoteobject</var> at the <strong class="pkg">SCSCP</strong> server, and returns <code class="keyw">true</code> or <code class="keyw">false</code> dependently on whether this action was successful or not.</p>
<p>Finally, we show an example when first we create a group on the service running on port 26133, and then identify it on the service running on port 26134:</p>
<p>Instead of transmitting the group to the client and then sending it as an argument to the second service, the latter service directly retrieves the group from the first service:</p>
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.21Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.