UDPSocketOpen

Opens a UDP socket, which relates a certain UDP source port to a certain ID.

Syntax

UDPSocketOpen( SocketID, Port, RecvQueueSize [optional], Interface [optional])

Remarks

UDPSocketOpen() opens a UDP "socket" which relates a certain UDP source port to a certain ID. This instruction returns an ID that can be passed to other UDPSocket type functions to send and receive data using this source port. UDP servers and clients do not really exist in the same way as with TCP, since UDP is connectionless, but generally a client will pass 0 for the source port, so that the operating system will assign it an ephemeral port. Servers (who are listening for connections from multiple remotes) will generally choose to specify a well known or registered port to listen for incoming datagrams and send response datagrams on.

Parameters

SocketID

A variable that holds the Socket ID that can be passed to other UDPSocket functions to operate on the socket or an error code. If negative, an error occurred (socket not opened). The values that can be returned are:

Code Description
>=0 Successful. This is the socket ID.
-1 Failed to allocate UDPSocket.
-2 Requested port in use.
-3  Limit of open ports reached.
-4 Port out of range.
-5 Invalid interface.

Type: Variable of type Long

Port

A non-ephemeral port to bind this socket to (1 - 49151). If 0 is passed, the operating system will bind this socket to an ephemeral port.

Type: Constant or Variable of type Long

Optional Parameters

RecvQueueSize

Specifies the maximum amount of messages that will be queued up for UDPSocketRecv on this particular socket. If maximum queue size is reached, incoming packets will be discarded. Thus, the user is encouraged to call UDPSocketRecv often. This parameter defaults to 5. If you are not interested in receiving any data on this socket, set this parameter to 0 to stop any incoming data from being buffered up.

Type: Constant or Variable of type Long

Interface

Specifies an interface to bind this socket to. By default, this socket will send and receive on all active interfaces and be affected by the IPRoute() instruction. If non-zero (this socket is bound to an interface), this socket will not be affected by IPRoute.

Value Description
0 Default behavior
1 Internal Ethernet.
2 CS I/O Interface(1) (NL201 by default)
CS I/O Interface(2) (NL241 by default)
4 Internal Wi-F
5 PPP

Type: Constant or Variable of type Long