https://m204wiki.rocketsoftware.com/index.php?title=Sample_Janus_Sockets_programs&feed=atom&action=historySample Janus Sockets programs - Revision history2024-03-29T11:23:46ZRevision history for this page on the wikiMediaWiki 1.40.1https://m204wiki.rocketsoftware.com/index.php?title=Sample_Janus_Sockets_programs&diff=59137&oldid=prevJAL: /* See also */2013-04-26T15:14:42Z<p><span dir="auto"><span class="autocomment">See also</span></span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:14, 26 April 2013</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l461">Line 461:</td>
<td colspan="2" class="diff-lineno">Line 461:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==See also==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==See also==</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[Janus Sockets User Language coding considerations]]</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><li>Socket-level interfaces:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><li>Socket-level interfaces:</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td></tr>
</table>JALhttps://m204wiki.rocketsoftware.com/index.php?title=Sample_Janus_Sockets_programs&diff=59117&oldid=prevJAL: /* See also */2013-04-25T19:13:55Z<p><span dir="auto"><span class="autocomment">See also</span></span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:13, 25 April 2013</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l461">Line 461:</td>
<td colspan="2" class="diff-lineno">Line 461:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==See also==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==See also==</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"><li>[[Sample Janus Sockets programs]]</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><li>Socket-level interfaces:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><li>Socket-level interfaces:</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><ul></div></td></tr>
</table>JALhttps://m204wiki.rocketsoftware.com/index.php?title=Sample_Janus_Sockets_programs&diff=59107&oldid=prevJAL: /* Print capturing example */2013-04-25T19:08:44Z<p><span dir="auto"><span class="autocomment">Print capturing example</span></span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:08, 25 April 2013</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l458">Line 458:</td>
<td colspan="2" class="diff-lineno">Line 458:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>End</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>End</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></p></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></p></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">==See also==</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><ul></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[Sample Janus Sockets programs]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>Socket-level interfaces:</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><ul></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[Janus Sockets $functions|$functions]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[Socket class]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ul></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>Higher-level interfaces: </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><ul></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[Email class]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[HTTP Helper|HTTP Helper classes]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[LDAP class]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[Janus FTP Server]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><li>[[Janus Telnet Server]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ul></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Janus Sockets]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Janus Sockets]]</div></td></tr>
</table>JALhttps://m204wiki.rocketsoftware.com/index.php?title=Sample_Janus_Sockets_programs&diff=50011&oldid=prevJAL2: Created page with "==Retrieving web pages: HTTP, HTML== The examples in this section show techniques for composing HTTP requests, sending them to a web server, and retrieving the response. The cu..."2012-02-14T22:52:31Z<p>Created page with "==Retrieving web pages: HTTP, HTML== The examples in this section show techniques for composing HTTP requests, sending them to a web server, and retrieving the response. The cu..."</p>
<p><b>New page</b></p><div>==Retrieving web pages: HTTP, HTML==<br />
The examples in this section show techniques for composing HTTP requests,<br />
sending them to a web server, and retrieving the response.<br />
<br />
The current specification for HTTP ([http:///www.w3.org/Protocols/rfc2616/rfc2616.html HTTP/1.1])<br />
gives something like the following simple structure for using HTTP:<br />
<ol><br />
<li>Client ("browser") sends a request, which contains:<br />
<ol><br />
<li>The request line, ended by CRLF (x'0D0A'), and containing:<br />
<ol><br />
<li>The method, for example, GET to get a web page<br />
<li>The ID, or "URL"<br />
<li>The protocol version, for example, HTTP/1.1<br />
</ol><br />
<li>Additional header lines, each ended by CRLF<br />
<li>An empty line, that is, an immediate CRLF<br />
<li>The body<br />
</ol><br />
<li>Server interprets the request and sends a response, which contains:<br />
<ol><br />
<li>The response status line, ended by CRLF, and containing:<br />
<ol><br />
<li>The HTTP version ID (for example, HTTP/1.1), followed by spaces<br />
<li>The status code number, followed by spaces<br />
<li>The status code message<br />
</ol><br />
<li>Additional header lines, each ended by CRLF<br />
<li>An empty line, that is, an immediate CRLF<br />
<li>The body<br />
</ol><br />
</ol><br />
<br />
Header lines contain a case-insensitive field name, followed by a colon (<tt>:</tt>),<br />
and spaces followed by the field value.<br />
<br />
The ASCII string of carriage-return followed by linefeed (0D0A) is<br />
used in the HTTP protocol to separate header lines and to separate the header from the body.<br />
The response body is the web "page,"<br />
which may contain a variety of data.<br />
Frequently, the page will contain HTML, which is frequently separated into<br />
"lines;" however, the separators of the lines are commonly either 0D0A, 0D, or 0A.<br />
Although this presents ambiguous parse tokens, as discussed in [[#Ambiguous PRSTOK strings|"Ambiguous PRSTOK strings"]],<br />
the pitfalls of the general request-response protocols do not apply with a single<br />
request-response when the only ambiguity occurs in the response stream.<br />
<br />
===Simple echo of HTTP/HTML===<br />
This example shows a complete program that communicates with a remote<br />
web server and that parses and prints the returned HTML stream.<br />
<br />
Note that the third argument to <var>[[$Sock_RecvPrs]]</var> is -1, which means that there<br />
is no limit to the length of each line parsed, hence no limit to the number of bytes discarded<br />
at the end of the line (only the first 78 bytes (<code>%s</code> size) of each line of HTML is examined<br />
by the <var class="product">User Language</var> program).<br />
[[#Echo of HTTP/HTML with continuation lines|"Echo of HTTP/HTML with continuation lines"]]<br />
has an example that examines complete lines, printing continuation lines as needed.<br />
<p class="code">JANUS DEFINE MYBROWSE * CLSOCK 60 REMOTE * 80 LINEND 0D0A<br />
JANUS START MYBROWSE<br />
Begin<br />
%socket Is Float<br />
%rc Is Float<br />
%host Is String Len 255<br />
%page Is String Len 255<br />
%s Is String Len 78<br />
%host = 'www.sirius-software.com'<br />
%page = 'main.html'<br />
<br />
%socket = $sock_conn('TEST', %host)<br />
If %socket Lt 0 Then<br />
Stop<br />
End If<br />
%rc = $sock_send(%socket, 'GET /')<br />
%rc = $sock_send(%socket, %page)<br />
%rc = $sock_sendln(%socket, ' HTTP/1.0')<br />
&#42; Null line indicates end of request:<br />
%rc = $sock_sendln(%socket, '')<br />
<br />
%s = $sock_set(%socket, 'PRSTOK', 'AMBIG|0D0A|0A|0D')<br />
Repeat<br />
%rc = $sock_recvprs(%socket, %s, -1)<br />
Print %s<br />
If %rc Le 0 Then<br />
Loop End<br />
End If<br />
End Repeat<br />
%rc = $sock_close(%socket)<br />
End<br />
</p><br />
<br />
===Echo of HTTP/HTML with continuation lines===<br />
This example shows a complete program that communicates with a remote<br />
web server and which parses and prints the returned HTML stream.<br />
This program differs from that in<br />
[[#Simple echo of HTTP/HTML|"imple echo of HTTP/HTML"] because it examines complete lines,<br />
printing continuation lines as needed.<br />
<br />
The fourth argument to <var>[[$Sock_RecvPrs]]</var> (<code>%x</code> in the example below) is<br />
the index of the separator string found in the received data.<br />
When this value is 0, it means that, within the data that has<br />
been received upon return from <var>$Sock_RecvPrs</var>, no separator has been found.<br />
This indicates one of the following:<br />
<ul><br />
<li>All data has been received (or all<br />
data within <var>RECVLIM</var>, which is not used in this example)<br />
<li>The limit set by its third argument (here defaulting to 0, which means<br />
the size of the second argument) caused <var>$Sock_RecvPrs</var> to return before it<br />
might have found a separator.<br />
</ul><br />
<br />
This information (<code>%x Eq 0</code>) works adequately for the example.<br />
<p class="code">JANUS DEFINE MYBROWSE * CLSOCK 60 REMOTE * 80 LINEND 0D0A<br />
JANUS START MYBROWSE<br />
Begin<br />
%socket Is Float<br />
%rc Is Float<br />
%x Is Float<br />
%host Is String Len 255<br />
%page Is String Len 255<br />
%s Is String Len 75<br />
%pre Is String Len 2<br />
%host = 'www.sirius-software.com'<br />
%page = 'main.html'<br />
<br />
%socket = $sock_conn('TEST', %host)<br />
If %socket Lt 0 Then<br />
Stop<br />
End If<br />
%rc = $sock_send(%socket, 'GET /')<br />
%rc = $sock_send(%socket, %page)<br />
%rc = $sock_sendln(%socket, ' HTTP/1.0')<br />
&#42; Null line indicates end of request:<br />
%rc = $sock_sendln(%socket, '')<br />
<br />
%s = $sock_set(%socket, 'PRSTOK', 'AMBIG|0D0A|0A|0D')<br />
%pre = ' '<br />
Repeat<br />
%rc = $sock_recvprs(%socket, %s, , %x)<br />
Print %pre And %s<br />
If %rc Le 0 Then<br />
Loop End<br />
End If<br />
%pre = ' '<br />
If %x Eq 0 Then<br />
%pre = '->'<br />
End If<br />
End Repeat<br />
%rc = $sock_close(%socket)<br />
End<br />
</p><br />
<br />
==Request-response protocol==<br />
The first parts of this section exhibit a very simple<br />
protocol which can be used between any two sockets platforms.<br />
This example is shown using <var class="product">Janus Sockets</var> for both the client and<br />
server, but either the client or the server portion can be easily<br />
implemented on any platform with a sockets interface.<br />
<br />
This protocol makes use of the <var>[[$Sock_RecvPrs]]</var> function to receive the<br />
client request and server response.<br />
The request consists of multiple strings, each<br />
separated by an "end of line" sequence.<br />
This is a natural sequence for various platforms;<br />
for example, you might want to copy the contents of a text file as some of the data in the request.<br />
<br />
In some environments, end of line is <code>X'0D'</code> and in others <code>X'0D0A'</code>.<br />
Since one line-end alternative is a prefix of another, it is necessary to<br />
use the <var>AMBIG</var> specification on the <var>PRSTOK</var> parameter.<br />
The last part of this section ([[#Ambiguous PRSTOK strings|"Ambiguous PRSTOK strings"]])<br />
discusses some considerations for ambiguous <var>PRSTOK</var> parameters.<br />
<br />
===Single request client code===<br />
This client sends a single request and receives a response.<br />
A request contains an action, followed by the data for the request,<br />
followed by a distinct line for the end of the request.<br />
After sending the request, it receives the response from the server.<br />
<br />
This example could easily be written for another sockets platform,<br />
and the data could be conveniently obtained from a text file.<br />
<br />
As discussed in [[#Ambiguous PRSTOK strings|"Ambiguous PRSTOK strings"]], it is important to use an<br />
unambiguous separator string at the end of the request, one that<br />
is not a prefix of any other separator.<br />
In our protocol, we are using a single byte of hex 07 (the ASCII "Bell" character) as this<br />
separator to "turn around" the connection from both the client and server perspective.<br />
<p class="code">JANUS DEFINE SOCKA * CLSOCK 10 REMOTE SOCKA_SRV 7733<br />
JANUS START SOCKA<br />
Begin<br />
%x Float<br />
%r Float<br />
%status String Len 10<br />
%x = $sock_conn('SOCKA')<br />
If %x Lt 0 Then<br />
Stop<br />
End If<br />
%r = $sock_sendln(%X, 'ACTION1')<br />
Fr Where RECTYPE = 'MYDATA'<br />
%r = $sock_sendln(%x, DATA)<br />
End For<br />
%r = $sock_sendln(%x, 'GO', 'LINEnd 07')<br />
%r = $sock_recvprs(%x, %status, , 'PRSTOK 07')<br />
If %status Ne 'GOOD' Then<br />
Stop<br />
End If<br />
%r = $sock_close(%x)<br />
</p><br />
<br />
===Single request server code===<br />
The server receives a single request and sends a response.<br />
See details about the protocol in [[#Single request client code|"Single request client code"]].<br />
<br />
<b>Note:</b><br />
As always, the connection initiating <var>SRVSOCK</var> processing is accessible as socket number 1.<br />
<p class="code">JANUS DEFINE SOCKS 7733 SRVSOCK 10 CMD 'INCLUDE SINGLE_REQ'<br />
JANUS START SOCKS<br />
PROCEDURE SINGLE_REQ<br />
Begin<br />
%r Float<br />
%sepx Float<br />
%data String Len 255<br />
%r = $sock_set(1, 'PRSTOK', 'AMBIG|0D0A|0D|0A|07')<br />
%r = $sock_set(1, 'LINEND', '07')<br />
%r = $sock_recvprs(1, %data)<br />
If %r Le 0 Then<br />
Stop<br />
End If<br />
If %data Eq 'ACTION1' Then<br />
Repeat<br />
%r = $sock_Recvprs(1, %data, %sepx)<br />
If %r Le 0 Then<br />
Stop<br />
Elseif %sepx Le 4 Then<br />
If %data Ne 'GO' Then<br />
%r = $sock_sendln(1, 'BAD')<br />
Else<br />
%r = $sock_sendln(1, 'GOOD')<br />
End If<br />
Stop<br />
End If<br />
... processing a line of data<br />
End Repeat<br />
Else If %data Eq ... other operation<br />
Repeat<br />
%r = $sock_recvprs(1, %data, %sepx)<br />
... (same structure as above)<br />
End Repeat<br />
Else If %data Eq ... other operations<br />
...<br />
End If<br />
%r = $sock_close(1)<br />
End<br />
END PROCEDURE<br />
</p><br />
<br />
===Multiple request client code===<br />
This client sends a series of requests and receives a response from each one.<br />
The protocol is the same as shown in [[#Single request client code|"Single request client code"]], except that<br />
at the end of the series of requests it sends a special action to<br />
indicate the end of the conversation.<br />
<br />
In this example, the use of the unambiguous separator at the end of<br />
the response is more important than in the previous example, because<br />
the server is going to receive after sending the response.<br />
With a single request-response protocol, as long as you are sure that<br />
the server will close the connection after sending the response, the<br />
client will receive the complete response even if it is terminated by an ambiguous separator.<br />
<br />
It is good practice, however, to use unambiguous separators to end<br />
each request and response, since, for example, the server may be poorly<br />
designed and the connection could stay open for an extended time.<br />
<p class="code">JANUS DEFINE SOCKA * CLSOCK 10 REMOTE SOCKA_SRV 7733<br />
JANUS START SOCKA<br />
Begin<br />
%x Float<br />
%r Float<br />
%status String Len 10<br />
%x = $sock_conn('SOCKA')<br />
If %x Lt 0 Then<br />
Stop<br />
End If<br />
%r = $sock_set(%x, 'PRSTOK', '07')<br />
Fr Where RECTYPE = 'REQUEST'<br />
%r = $sock_sendln(%x, REQ_TYPE)<br />
D: FEO DATA_LINE<br />
%r = $sock_sendln(%x, VALUE IN D)<br />
End For<br />
%r = $sock_sendln(%x, 'GO', 'LINEND 07')<br />
%r = $sock_recvprs(%x, %status)<br />
If %status Ne 'GOOD' Then<br />
Stop<br />
End If<br />
End For<br />
%r = $sock_sendln(%x, 'DONE')<br />
%r = $sock_close(%x)<br />
</p><br />
<br />
===Multiple request server code===<br />
The server receives a series of requests and sends a response for each one.<br />
The protocol is the same as shown in [[#Single request client code|"Single request client code"]], except that<br />
at the end of the series of requests the client sends a special action to<br />
indicate the end of the conversation.<br />
<br />
<b>Note:</b><br />
As always, the connection initiating <var>SRVSOCK</var> processing is<br />
accessible as socket number 1.<br />
<p class="code">JANUS DEFINE SOCKS 7733 SRVSOCK 10 CMD 'INCLUDE MULTIPLE_REQ'<br />
JANUS START SOCKS<br />
PROCEDURE MULTIPLE_REQ<br />
Begin<br />
%r Float<br />
%sepx Float<br />
%data String Len 255<br />
%r = %sock_set(1, 'PRSTOK', 'AMBIG|0D0A|0D|0A|07')<br />
%r = %sock_set(1, 'LINEND', '07')<br />
Repeat<br />
%r = %sock_recvprs(1, %data)<br />
If %r Le 0 Then<br />
Loop End<br />
End If<br />
If %data Eq 'DONE' Then<br />
Loop End<br />
Elseif %data Eq 'ACTION1' Then<br />
Repeat<br />
%r = %sock_recvprs(1, %data, %sepx)<br />
If %r Le 0 Then<br />
Stop<br />
Elseif %sepx Eq 4 Then<br />
If %data Eq 'DONE' Then<br />
%r = %sock_sendln(1, 'BAD')<br />
Loop End<br />
End If<br />
%r = %sock_sendln(1, 'GOOD')<br />
Loop End<br />
End<br />
... processing a line of data<br />
End Repeat<br />
Else If %data Eq ... another operation<br />
Repeat<br />
%r = %sock_recvprs(1, %data, %sepx)<br />
... (same structure as above)<br />
End Repeat<br />
Else If %data Eq ... other operations<br />
...<br />
End If<br />
End Repeat<br />
%r = %sock_close(1)<br />
End<br />
END PROCEDURE<br />
</p><br />
<br />
===Ambiguous PRSTOK strings===<br />
In the example code shown in the preceding sections, the lines of data are sent with<br />
either CRLF, CR, or LF (0D0A|0D|0A) separating them, but the line that signals the end of<br />
a request is terminated with hex 07.<br />
The separators <code>0D0A</code> and <code>0D</code> are '''ambiguous''' because <code>0D</code> is a<br />
prefix of <code>0D0A</code>.<br />
When a <code>0D</code> is received, <var class="product">Janus Sockets</var> waits until it receives an additional byte<br />
to distinguish which of the two separators was sent.<br />
The unambiguous 07 is used in the example in [[#Multiple request client code|"Multiple request client code"]]<br />
to end the <code>GO</code> line, because using an ambiguous separator when<br />
going from send to receive mode can cause both sides to wait for data that is not forthcoming.<br />
<br />
In a request-response protocol, when one side finishes sending (the<br />
client finishes a request, or the server finishes a response), it then<br />
does a receive (the client to get the response, the server to get the next request).<br />
When either side does the receive, it must be ensured that the other side does not<br />
continue to wait for data on its own receive.<br />
Otherwise, both sides are receiving and nothing is being sent for them to receive.<br />
In this case, they could wait forever, until the <var>TIMEOUT</var> value expires at one side or the other,<br />
or until (using <var class="product">Model 204</var>) one side is bumped.<br />
<br />
If the server accepts 0D0A|0D|0A (or even just 0D0A|0D) as the terminator<br />
of the <code>GO</code> line, and the client sends <code>0D</code> as its <var>LINEND</var> and<br />
then does a receive, the server will wait to receive a byte after the<br />
<code>0D</code> to determine whether the separator was <code>0D0A</code> or just <code>0D</code>.<br />
This situation where both sides wait forever is avoided by using an unambiguous separator<br />
(<code>07</code> in this case) as the terminator of the <code>GO</code> line.<br />
Similarly, the multiple request server uses the unambiguous <code>07</code> to terminate the response, so that<br />
the client can send the next request.<br />
<br />
If possible, use unambiguous separators when designing your protocols.<br />
If that is very inconvenient, such as the case of copying text files with the<br />
ambiguous linend 0D0A|0D|0A strings, you must use the <code>AMBIG|</code> specification<br />
at the start of your <var>PRSTOK</var> string, and you should take special care when composing<br />
the terminator of a line that is the last one before a switch to do a receive.<br />
The <code>AMBIG|</code> indicator highlights the necessity to ensure that your<br />
protocol, that is, the sockets application processing logic, avoids the pitfalls<br />
introduced by ambiguous separators.<br />
<br />
Since <code>0A</code> and <code>0D0A</code> are not prefixes of another separator, either<br />
could be used as <code>GO</code> terminator, if the line <code>GO</code> is guaranteed<br />
not to occur as a data line.<br />
The server code (for example,<br />
in [[#Single request server code|"Single request server code"]]) uses the extra protection of a unique<br />
line and a unique separator to double-check that the client is not violating the protocol.<br />
<br />
Again, the "wait forever" problem that ambiguous separators may produce only<br />
applies to a separator that occurs at a send/receive boundary.<br />
Thus, as mentioned in [[#Retrieving web pages: HTTP, HTML|"Retrieving web pages: HTTP, HTML"]], a<br />
single request-response protocol presents no problems if the only ambiguity<br />
is in the response stream.<br />
<br />
Other than "wait forever" problems, the other question raised by ambiguous separators concerns null "lines."<br />
The simple rule is that the longest separator possible is chosen.<br />
So, consider the following somewhat silly client code that "hand codes" its separators:<br />
<p class="code">%r = $sock_send(%sok, 'Line 1')<br />
%r = $sock_send(%sok, $x2c('0D'), 'BINARY')<br />
%line2 = ''<br />
%r = $sock_send(%sok, %line2)<br />
%r = $sock_send(%sok, $X2C('0A'), 'BINARY')<br />
%r = $sock_send(%sok, 'Line 3')<br />
%r = $sock_send(%sok, $x2c('0D07'), 'BINARY')<br />
</p><br />
If the corresponding server code is:<br />
<p class="code">%r = $sock_set(1, 'PRSTOK', 'AMBIG|0D0A|0D|0A|07')<br />
Repeat<br />
%r = $sock_recv(1, %targ)<br />
If %r Le 0 Then<br />
Loop End<br />
End<br />
Print 'Length ' $Len(%targ) ': ' %targ<br />
</p><br />
The results will be:<br />
<p class="code">Length 6: Line 1<br />
Length 6: Line 3<br />
Length 0:<br />
</p><br />
What might appear to be the sending of three lines by the client, with<br />
the second line null, is actually seen by the server as two lines, because<br />
the hexadecimal string <code>0D0A</code> is seen as one separator, not two.<br />
<br />
===Print capturing example===<br />
<br />
This example shows the use of print capturing.<br />
This application uses <var>WRITE IMAGE ON TERMINAL</var> for output, which might<br />
be appropriate, for example, in a <var>BATCH2</var> input stream.<br />
<br />
Note that the final <var>Print</var> statement goes to the terminal, since<br />
there are no sockets with print captured at that point.<br />
<br />
For more information about print capturing, see [[$Sock_Capture#Print capturing hierarchy and other considerations|"Print capturing hierarchy and other considerations"]].<br />
<p class="code">Begin<br />
IMAGE LIN<br />
S IS STRING LEN 255<br />
END IMAGE<br />
OPEN TERMINAL FOR OUTPUT<br />
%sock = $sock_conn('SOCKEM')<br />
If %sock Lt 0 Then<br />
Stop<br />
End If<br />
%s = $sock_capture(%sock, 'ON')<br />
Prepare Image LIN<br />
Print 'Hello, world!'<br />
%lin:S = 'Look at me - I sent a line!'<br />
Write Image LIN On Terminal<br />
Print 'Goodbye, world!'<br />
%x = $sock_close<br />
Print 'Mission accomplished'<br />
End<br />
</p><br />
<br />
[[Category:Janus Sockets]]</div>JAL2