SocketServerStart

(Engine-Level Function)

Description: Starts a TCP/IP or UDP socket server and returns a handle to it.
Returns: Handle
Usage: Script Only.
Function Groups: Stream and Socket
Related to: ClientSocket | CloseStream | ServerSocket | SocketAttribs | SocketServerEnd | SocketWait | SRead | SWrite | LargeSocketWrite
Format: SocketServerStart(Family, Port, TransmitLen, ReceiveLen, NoDelay[, ProtocolFilter] )
Parameters:  
Family
Required. Any numeric expression for the protocol family

Family

Description

0

TCP/IP

1

UDP

Port
Required. Any numeric expression for the port number to offer.
TransmitLen
Required. Any numeric expression for the number of bytes to buffer when transmitting. The value must be a signed long integer, where only positive values are useful.
If the application is running on a operating system of Windows 7 / Server 2008 R2, or later, and the value is set to zero, then Windows will manage the appropriate buffer size for the link speed and latency.
If you set the buffer size, the value should match or be larger than the largest message that is expected.
A high bandwidth / high latency link will require a larger size to achieve optimum efficiency, but the exact size can be determined only by empirical testing..
ReceiveLen
Required. Any numeric expression for the maximum number of bytes to buffer by VTScada when receiving. Additional buffering will be handled by WinSock.
The value must be a signed long integer, where only positive values are useful (an error will be returned if the value is not greater than zero). The value should match or be larger than the largest message that is expected.
A high bandwidth / high latency link will require a larger size to achieve optimum efficiency, but the exact size can be determined only by empirical testing.
NoDelay
Required. Any logical expression. If true, anything written to a socket started by this server will be flushed immediately. If false, packets are coalesced into larger packets to reduce network loading. This parameter should normally be false.
ProtocolFilter

An optional array that specifies what filtering should be applied to socket connections. The order in the ProtocolFilter array determines priority.

Each filter item consists of two elements where the first is the filter type ("SSL", "VIC", "NULL" and "PROXY") The second is a value dependent upon the filter type, noting that there is no second value for "VIC" and "NULL" types. The certificate subject name is not normally used on a client connection.

Examples:
For TLS/SSL the value is the subject name in the certificate, given as "CN=host.example.com".
For PROXY it is a string.

PFilter = New(2);
PFilter[0] = New(2);
PFilter[0][0] = "SSL";
PFilter[0][1] = "CN=host.example.com";
PFilter[1] = New(2);
PFilter[1][0] = "NULL";
PFilter[1][1] = "";

Comments:

If the parameters are all valid and the socket function fails a negative error code is returned. Error codes can be found in ClientSocket.


If the handle to the socket is orphaned, the equivalent to a SocketServerEnd is performed
RecieveLen and NoDelay apply to streams created by inbound connections (TCP) or datagrams (UDP), not to the listener.
The handle returned can be used by the SocketWait or SocketServerEnd functions.