ServerSocket (Socket function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Created page with " <span class="pageSubtitle"><section begin=dpl_desc/><section end=dpl_desc/></span> ServerSocket function <p> <var>ServerSocket</var> is a member of t...")
 
(Automatically generated page update)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{Template:Socket:ServerSocket subtitle}}
<span class="pageSubtitle"><section begin=dpl_desc/><section end=dpl_desc/></span>
[[Category:Socket methods|ServerSocket function]]
<p>
<var>ServerSocket</var> is a member of the <var>[[Socket class|Socket]]</var> class.
</p>


This [[Notation conventions for methods#Shared members|shared]] method obtains a reference to a
This [[Notation conventions for methods#Shared members|shared]] method obtains a reference to a
<var>Socket</var> object for the server socket (socket number 1 in the <var>$Sock_xxx</var> API,
<var>Socket</var> object for the server socket (socket number 1 in the [[Janus Sockets $functions|$Sock_xxx API]],
as described in [[Janus Sockets User Language coding considerations#Client versus Server Socket programming|"Client versus Server Socket programming"]].
as described in [[Janus Sockets User Language coding considerations#Client versus Server Socket programming|"Client versus Server Socket programming"]].
It returns a reference to a <var>Socket</var> object instance, which can then be
It returns a reference to a <var>Socket</var> object instance, which can then be
Line 14: Line 9:


==ServerSocket syntax==
==ServerSocket syntax==
<p class="pre"> %so = %(Socket):ServerSocket
{{Template:Socket:ServerSocket syntax}}
</p>
 
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%so</th>
<tr><th>%socket</th>
<td>A declared socket object or a reference to a <var>Socket</var> object.
<td>A declared socket object or a reference to a <var>Socket</var> object.
</td></tr>
</td></tr>
<tr><th>%(Socket)</th>
<tr><th><var class="nobr">%(Socket)</var></th>
<td>The class name in parentheses denotes a shared method. Specifying <code>%(Socket):</code> is not the only way to invoke the method (see [[??]] refid=themeth.).
<td>The class name in parentheses denotes a [[Notation conventions for methods#Shared methods|virtual constructor]] method. See [[#Usage notes|"Usage notes]]" below, for more information about invoking a <var>Socket</var> constructor.
 
</table>
</td></tr></table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li><var>ServerSocket</var> is a [[Object variables#Virtual Constructor methods|virtual constructor]] and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is <var>Null</var>:
<p class="code">%sock = ServerSocket
%sock = %(Socket):ServerSocket
%sock = %sock:ServerSocket
</p>
<li>After <var>ServerSocket</var> returns, the socket is no longer accessible by its
<li>After <var>ServerSocket</var> returns, the socket is no longer accessible by its
socket number (1).
socket number (1).
Line 36: Line 37:
</ul>
</ul>


==Example==
==Examples==


In the following code fragment, a server socket receives data and replies to its client.
In the following code fragment, a server socket receives data and replies to its client.
Line 55: Line 56:
  ...
  ...
</p>
</p>
{{Template:Socket:ServerSocket footer}}

Latest revision as of 01:00, 16 February 2014

Get a reference to the server socket (Socket class)


This shared method obtains a reference to a Socket object for the server socket (socket number 1 in the $Sock_xxx API, as described in "Client versus Server Socket programming". It returns a reference to a Socket object instance, which can then be used with instance method calls to access the server socket. ServerSocket has no equivalent $function.

ServerSocket syntax

%socket = [%(Socket):]ServerSocket

Syntax terms

%socket A declared socket object or a reference to a Socket object.
%(Socket) The class name in parentheses denotes a virtual constructor method. See "Usage notes" below, for more information about invoking a Socket constructor.

Usage notes

  • ServerSocket is a virtual constructor and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is Null:

    %sock = ServerSocket %sock = %(Socket):ServerSocket %sock = %sock:ServerSocket

  • After ServerSocket returns, the socket is no longer accessible by its socket number (1). To access the socket by its number again, use GetSocketNumber.
  • ServerSocket can be used to obtain a Socket object reference for a socket already created by $Sock_Conn, or it can operate in an entirely object-oriented application.

Examples

In the following code fragment, a server socket receives data and replies to its client.

Begin %r Float %sepx Float %data is String len 255 %servsock is Object Socket %servsock = %(Socket):ServerSocket %r = %servsock:Set('PRSTOK', 'AMBIG|0D0A|0D|0A|07') %r = %servsock:Set('LINEND', '07') %r = %servsock:ReceiveAndParse(%data) If %r le 0 Then ... If %data eq 'Hello' Then ... %r = %servsock:SendWithLineEnd('OK') ...