BRL.Socket: Functions Source  


Functions

CreateUDPSocketCreate a UDP socket
CreateTCPSocketCreate a TCP socket
CloseSocketClose a socket
BindSocketBind a socket to a local port
ConnectSocketConnect a socket to a remote ip and port
SocketListenStart listening at a socket
SocketAcceptAccept new connections on a listening socket
SocketConnectedGet socket connection status
SocketReadAvailGet number of bytes available for reading from a socket
SocketLocalIPGet local ip of a socket
SocketLocalPortGet local port of a socket
SocketRemoteIPGet remote ip of a socket
SocketRemotePortGet remote port of a socket
DottedIPConvert an ip address to a dotted string
HostIpConvert a host name to an ip address
HostIpsGet all ip addresses for a host name
HostNameConvert a host ip address to a name

Function reference

Function CreateUDPSocket:TSocket()
ReturnsA new socket
DescriptionCreate a UDP socket
Information The new socket is not bound to any local or remote address.

Function CreateTCPSocket:TSocket()
ReturnsA new socket
DescriptionCreate a TCP socket
Information The new socket is not bound to any local or remote address.

Function CloseSocket( socket:TSocket )
DescriptionClose a socket
Information All sockets should eventually be closed. Once closed, a socket can no longer be used.

Function BindSocket( socket:TSocket,localPort )
ReturnsTrue if successful, otherwise false
DescriptionBind a socket to a local port
Information If localPort is 0, a new local port will be allocated. If localPort is not 0, BindSocket will fail if there is already an application bound to localPort.

Function ConnectSocket( socket:TSocket,remoteIp,remotePort )
ReturnsTrue if successful, otherwise false
DescriptionConnect a socket to a remote ip and port
Information For both UDP and TCP sockets, ConnectSocket will fail if the specified ip address could not be reached.

In the case of TCP sockets, ConnectSocket will also fail if there is no application listening at the remote port.

Function SocketListen( socket:TSocket,backlog=0 )
DescriptionStart listening at a socket
Information The specified socket must be a TCP socket, and must already be bound to a local port.

Function SocketAccept:TSocket( socket:TSocket,timeout=0 )
ReturnsA new socket, or Null if no connection was made in the specified timeout
DescriptionAccept new connections on a listening socket
Information The specified socket must be a TCP socket, and must be listening.

Function SocketConnected( socket:TSocket )
ReturnsTrue if socket is connected
DescriptionGet socket connection status
Information SocketConnected allows you to determine if a TCP connection is still alive or has been remotely closed.

SocketConnected should only be used with TCP sockets that have already connected via ConnectSocket or SocketAccept.

Function SocketReadAvail( socket:TSocket )
ReturnsNumber of bytes that may be read without causing the socket to block
DescriptionGet number of bytes available for reading from a socket

Function SocketLocalIP( socket:TSocket )
DescriptionGet local ip of a socket

Function SocketLocalPort( socket:TSocket )
DescriptionGet local port of a socket

Function SocketRemoteIP( socket:TSocket )
DescriptionGet remote ip of a socket

Function SocketRemotePort( socket:TSocket )
DescriptionGet remote port of a socket

Function DottedIP$( ip )
ReturnsDotted string version of ip address
DescriptionConvert an ip address to a dotted string

Function HostIp( HostName$,index=0 )
ReturnsHost ip address, or 0 if host not found
DescriptionConvert a host name to an ip address

Function HostIps:Int[]( HostName$ )
ReturnsArray of host ips, or Null if host not found
DescriptionGet all ip addresses for a host name

Function HostName$( HostIp )
ReturnsName of host, or Null if host not found
DescriptionConvert a host ip address to a name