GetSocketObject (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> GetSocketObject function <p> <var>GetSocketObject</var> is a membe...")
 
m (1 revision)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:Socket:GetSocketObject subtitle}}


<span class="pageSubtitle"><section begin=dpl_desc/><section end=dpl_desc/></span>
<var>GetSocketObject</var> returns a <var>Socket</var> object for a given socket number.
[[Category:Socket methods|GetSocketObject function]]
It returns a reference to an instance of a <var>Socket</var> object, which can then be used with instance method calls.
<p>
<var>GetSocketObject</var> is a member of the <var>[[Socket class|Socket]]</var> class.
</p>


This [[Notation conventions for methods#Shared members|shared]]
method returns a <var>Socket</var> object for a given socket number.
It returns a reference to an instance of a
<var>Socket</var> object, which can then be used with instance method calls.
==Syntax==
==Syntax==
<p class="syntax">%so = %(Socket):GetSocketObject(socketnum)
{{Template:Socket:GetSocketObject 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><b>%(Socket</b>)</th>
<tr><th><var>[%(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 optional class name in parentheses denotes a [[Notation conventions for methods#Shared methods|virtual constructor]] method. See "Usage notes," below, for more information about invoking a <var>Socket</var>constructor.</td></tr>
</td></tr>
 
<tr><th>socketnum</th>
<tr><th>number</th>
<td>The number of a socket that was created with <var>[[$Sock_Conn]]</var>.
<td>The number of a socket that was created with <var>[[$Sock_Conn]]</var>.


Line 28: Line 22:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li><var>GetSocketObject</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 null:
<p class="code">%sock = GetSocketObject(<var class="term">num</var>)
%sock = %(Socket):GetSocketObject(<var class="term">num</var>)
%sock = %sock:GetSocketObject(<var class="term">num</var>)
</p>     
<li><var>GetSocketObject</var> is designed for adding <var>Socket</var> object code to an existing
<li><var>GetSocketObject</var> is designed for adding <var>Socket</var> object code to an existing
$Sock_xxx application, that is, for
$Sock_xxx application, that is, for
Line 63: Line 64:
<p class="code">The %sockhrb status is: CONN
<p class="code">The %sockhrb status is: CONN
</p>
</p>
{{Template:Socket:GetSocketObject footer}}

Latest revision as of 20:23, 30 November 2011

Get a socket object for the given socket number (Socket class)


GetSocketObject returns a Socket object for a given socket number. It returns a reference to an instance of a Socket object, which can then be used with instance method calls.

Syntax

%socket = [%(Socket):]GetSocketObject( number)

Syntax terms

%socket A declared socket object or a reference to a Socket object.
[%(Socket):] The optional class name in parentheses denotes a virtual constructor method. See "Usage notes," below, for more information about invoking a Socketconstructor.
number The number of a socket that was created with $Sock_Conn.

Usage notes

  • GetSocketObject 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 = GetSocketObject(num) %sock = %(Socket):GetSocketObject(num) %sock = %sock:GetSocketObject(num)

  • GetSocketObject is designed for adding Socket object code to an existing $Sock_xxx application, that is, for instantiating a socket from a socket number returned from $Sock_Conn. If you are building an entirely object-oriented socket application, use the New constructor.
  • After GetSocketObject returns, the socket is no longer accessible by its socket number. To access the socket by its number again, use GetSocketNumber.
  • If the object returned by a GetSocketObject invocation is the method object for a subsequent GetSocketNumber invocation, the NOCLOSE setting of the original numbered socket is applied to the numbered socket returned by GetSocketNumber. For information about NOCLOSE, see Set.

Example

In the following example,a socket created with $Sock_Conn is converted to a Socket object.

JANUS DEFINE PIPE * CLSOCK 8 REMOTE * * SOCKPMAX 10 JANUS START PIPE Begin %nums Is String Len 16 %sockhrb object Socket %CONN is float %CONN = $SOCK_CONN('PIPE', 'www.whrb.org', 80) %nums = %(Socket):Num('OPEN') %sockhrb = %(Socket):GetSocketObject(%nums) Print 'The %sockhrb status is: ' %sockhrb:Info('STAT') End

The example result is:

The %sockhrb status is: CONN