Socket class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
The <var>Socket</var> object is a coding alternative to using the $Sock_xxxx
The <var>Socket</var> object is a coding alternative to using the $Sock_xxxx functions.
functions.
An application written with the <var>Socket</var> object does not need to manage or refer to socket numbers.
An application written with the <var>Socket</var> object does not
need to manage or refer to socket numbers.
An instance of a <var>Socket</var>
An instance of a <var>Socket</var>
is essentially an object style reference to a <var>Socket</var> number.
is essentially an object style reference to a <var>Socket</var> number.
Both client and server applications may be written using the <var>Socket</var>
Both client and server applications may be written using the <var>Socket</var> object.
object.


'''Note:'''
'''Note:'''
Line 14: Line 11:
provided in <var class="product">[[Janus SOAP User Language Interface|"Janus SOAP User Language Interface"]]</var>.
provided in <var class="product">[[Janus SOAP User Language Interface|"Janus SOAP User Language Interface"]]</var>.
   
   
This article is primarily concerned with how to use the individual
There are some restrictions on the order in which the <var>Socket</var> object methods are
<var>Socket</var> object methods.
There are some restrictions on the order in which the methods are
used: for example, a socket port must be connected before data is sent using it,
used: for example, a socket port must be connected before data is sent using it,
and data may not be sent after the FIN indicator is sent.
and data may not be sent after the FIN indicator is sent.
Line 22: Line 17:
see [[Janus Sockets User Language coding considerations|"Janus Sockets User Language coding considerations"]].
see [[Janus Sockets User Language coding considerations|"Janus Sockets User Language coding considerations"]].
   
   
__TOC__
==Using Socket methods and $Sock_xxx functions==
Most of the <var>Socket</var> methods have analogous $functions,
Most of the <var>Socket</var> methods have analogous $functions,
and <var>Socket</var> objects may be used in code intermixed
and <var>Socket</var> objects may be used in code intermixed
with $Sock_xxx functions and socket numbers ("in peaceful coexistence").
with $Sock_xxx functions and socket numbers ("in peaceful coexistence").
   
   
In the individual <var>Socket</var> method description pages (see [[List of Socket methods]]),
In the individual <var>Socket</var> method description pages (see [[List of Socket methods|"List of Socket methods"]]),
if a <var>Socket</var> method is described as equivalent to a $Sock_xxx function,
if a <var>Socket</var> method is described as equivalent to a $Sock_xxx function,
the method has the same argument list as the $funtion, with one exception: the method has no socket number argument,
the method has the same argument list as the $funtion, with one exception: the method has no socket number argument,
Line 70: Line 68:
You use the <var>[[Close (Socket function)|Close]]</var> method
You use the <var>[[Close (Socket function)|Close]]</var> method
to close the socket and discard the <var>Socket</var> object.
to close the socket and discard the <var>Socket</var> object.
==List of Socket methods==
The [[List of Socket methods|"List of Socket methods"]] shows all the class methods.


[[Category:Janus Sockets]]
[[Category:Janus Sockets]]

Revision as of 00:17, 24 December 2011

The Socket object is a coding alternative to using the $Sock_xxxx functions. An application written with the Socket object does not need to manage or refer to socket numbers. An instance of a Socket is essentially an object style reference to a Socket number. Both client and server applications may be written using the Socket object.

Note: To use the Socket object, you must have licensed Janus Sockets and Janus SOAP. The Sirius object-oriented alternative to $functions is designed for Janus SOAP applications only, and information about using Sirius objects is provided in "Janus SOAP User Language Interface".

There are some restrictions on the order in which the Socket object methods are used: for example, a socket port must be connected before data is sent using it, and data may not be sent after the FIN indicator is sent. For more information about Janus Sockets programming, see "Janus Sockets User Language coding considerations".

Using Socket methods and $Sock_xxx functions

Most of the Socket methods have analogous $functions, and Socket objects may be used in code intermixed with $Sock_xxx functions and socket numbers ("in peaceful coexistence").

In the individual Socket method description pages (see "List of Socket methods"), if a Socket method is described as equivalent to a $Sock_xxx function, the method has the same argument list as the $funtion, with one exception: the method has no socket number argument, since the socket is implied by the object instance.

To simplify the conversion of existing Janus Sockets code, two transition methods are provided:

These transition methods let you gradually convert an existing application to use Socket objects.

Creating and destroying Socket objects

The Socket object constructor, the New method, creates an instance of a Socket object. The object created with New is a reference to a connection to a remote host using a Janus client socket. The ServerSocket method obtains a reference to a Socket object for a server socket.

The following is an example of the New constructor:

%socko is object Socket %socko = New(clientportname, host, port [, ssl])

If the connect fails, the object variable is set to null, and $Statusd is set to what would be the return code value if the same error had happened with $Sock_Conn, the Janus Sockets. $function that creates a socket connection.

To obtain information about any errors that occur while attempting to construct a Socket object instance, here is an error handler that can be used after the New constructor:

If %socko Is Null Then Print 'Error:' And $Statusd Stop End If

Note: An explicit Discard of the Socket object is not permitted. You use the Close method to close the socket and discard the Socket object.

List of Socket methods

The "List of Socket methods" shows all the class methods.