Socket class: Difference between revisions
mNo edit summary |
|||
Line 1: | Line 1: | ||
The <var>Socket</var> object is a coding alternative to using the $ | The <var>Socket</var> object is a coding alternative to using the [[Janus Sockets $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> |
Revision as of 23:09, 14 February 2012
The Socket object is a coding alternative to using the Janus Sockets $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:
- GetSocketNumber gives the socket number for an object instance.
- GetSocketObject creates an object instance for a given socket number.
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.