SIMPOL Documentation

tcpsocketserver

Description

A tcpsocketserver object can only be created via a call to the new() method. This object provides TCP/IP socket support for communication as a server. It can be the basis of any TCP/IP-based server, such as a web server, mail server, etc.

Type Tags

None

Object Value

Objects of type tcpsocketserver have no value, and it is an error to try to get or set this value.

tcpsocketserver.new()

Description

Creates a TCP/IP socket that is sitting on the requested port. It doesn't actually listen on the port until the listen() method is called. When a connection occurs on the port where the object is listening, then a new thread will be started at the function passed as a reference to the listen() method. That function must take a tcpsocket object as the first parameter. A single object can have multiple listeners in different threads.

Prototype

tcpsocketserver.new ( integer port, integer error )

Parameters

ParameterDefault valueType nameDescription
portNoneinteger The local port number to use. This parameter is required and must be in the range 1-65535.
error.nulinteger Specifies an object which is used to output any error code generated during creation of the tcpsocketserver object. If error is not specified or is .nul then any error which occurs during object creation will halt the program. If an error object is specified and an error occurs during object creation then the error code is output into that object and the new method returns .nul.

Properties

PropertyTypeDescription
_type(*) This property is provided for use by the user to attach any object of any type to the type in which this property is provided.
__type(*) This property is provided for use by the user to attach any object of any type to the type in which this property is provided. It has the additional feature of being marked with the resolve keyword, so that object resolution can continue down this property.
listeningboolean A read-only boolean showing whether or not the server is currently listening.
typetype Specifies the tcpsocketserver type object.

Methods

break()

Description

Breaks out of all listens associated with the object.

Prototype

tcpsocketservervar.break ()

Parameters

None

listen()

Description

This starts the object listening on the socket. When a connection is made a new thread is started at the function passed in the function parameter. The function must accept a tcpsocket as the first parameter and it may have a second parameter of any type that matches the type passed to the reference parameter (if specified).

Prototype

tcpsocketservervar.listen ( function function, type(*) reference, integer timeout, integer error )

Parameters
ParameterDefault valueType nameDescription
functionNonefunction The reference to the function to be called upon a successful connection.
reference.nultype(*) This is an optional object reference that will be passed to the function upon a successful connection. This can be a reference to an object of user-defined type to pass multiple pieces of information to the function.
timeout0integer The time in microseconds to listen before returning.
error.nulinteger Specifies an object that is used to output any error code generated during the execution of the method. This parameter must be an object, not an integer value. If error is not specified or is .nul then any error that occurs during object creation will halt the program. If an error object is specified and an error occurs during execution then the error code is output into that object and the method returns .nul.