Num (Socket function)

From m204wiki
Revision as of 21:35, 8 November 2011 by Admin (talk | contribs) (1 revision)
Jump to navigation Jump to search

<section begin=dpl_desc/><section end=dpl_desc/>

Num is a member of the Socket class.

This shared method retrieves the socket numbers of the set of sockets you select. For Socket objects, it implicitly executes a GetSocketNumber. The Num function has an effect similar to $Sock_Num.

Syntax

%numstr = %(Socket):Num[(selection)]

Syntax terms

%numstr Return string, which is to contain blank-separated socket numbers.
%(Socket) The class name in parentheses denotes a shared method. Specifying %(Socket): is not the only way to invoke the method (see ?? refid=themeth.).
selection The socket numbers to return: any combination of the following strings separated by OR, and each optionally prefixed by NOT:
ANY Return all in-use sockets [default].
CONN Return sockets enabled for sending in both directions.
FINR Return sockets on which local partner is enabled for sending but remote stopped sending ("FIN received").
FINS Return sockets on which remote partner is enabled for sending but local stopped sending ("FIN sent").
FINBOTH Return OPEN sockets on which remote and local partners both stopped sending ("FIN sent and received").
RESET Return in-use but no longer connected sockets.
OPEN Return OPEN sockets; this is equivalent to either of the following:
  • NOT RESET
  • CONN OR FINR OR FINS OR FINBOTH
CAPTURE Return sockets (OPEN or not) for which print capturing is on.
CAPOPEN Return OPEN sockets for which print capturing is on.

If NOT prefixes one of the above specifications, all in-use sockets (excluding the specified set) are included in the selected set. With multiple terms separated by OR, the specified sets are combined by the set union operation.

Usage notes

  • The Num method returns a blank-delimited string containing the numbers of the requested sockets in ascending order.
  • The Num method is not affected by any ONRESET setting.

Examples

  1. In the following example, %nums contains the blank-delimited numbers of (all) the open sockets:

    JANUS DEFINE PIPE * CLSOCK 5 REMOTE * * SOCKPMAX 2 JANUS START PIPE Begin %nums Is String Len 255 %sockamp object Socket %sockwga object Socket %sockamp = New('PIPE', 'www.ampas.org', 80) If %sockamp Is Null Then Print 'Error:' And $STATUSD Stop End If %sockwga = New('PIPE', 'www.wga.org', 80) If %sockwga Is Null Then Print 'Error:' And $STATUSD Stop End If %nums = %(Socket):Num Print 'The socket numbers are: ' %nums %sockamp:Close %sockwga:Close End

    The example result is:

    The socket numbers are: 2 3

  2. The following example shows another way to retrieve the list of all OPEN socket numbers:

    %nums = %(Socket):Num('NOT RESET')

  3. The following example shows how to retrieve the list of all OPEN socket numbers that have not received the FIN indicator:

    %nums = %(Socket):Num('CONN OR FINS')