Unit sdl2_net

Description

SDL_net: An example cross-platform network library for use with SDL Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TIPaddress  
Record TSDLNet_GenericSocket  
Record TSDLNet_SocketSet  
Record TUDPPacket  
Record TUDPSocket  
Record _TCPSocket  

Functions and Procedures

function SDLNet_AddSocket(set_: TSDLNet_SocketSet; sock: TSDLNet_GenericSocket): cint cdecl; external SDLNet_LibName;
function SDLNet_AllocPacket(size: cint): PUDPPacket cdecl; external SDLNet_LibName;
function SDLNet_AllocPacketV(howmany: cint; size: cint): PPUDPPacket cdecl; external SDLNet_LibName;
function SDLNet_AllocSocketSet(maxsockets: cint): TSDLNet_GenericSocket cdecl; external SDLNet_LibName;
function SDLNet_CheckSockets(set_: TSDLNet_SocketSet; timeout: cuint32): cint cdecl; external SDLNet_LibName;
function SDLNet_DelSocket(set_: TSDLNet_SocketSet; sock: TSDLNet_GenericSocket): cint cdecl; external SDLNet_LibName;
procedure SDLNet_FreePacket(packet: PUDPPacket) cdecl; external SDLNet_LibName;
procedure SDLNet_FreePacketV(packetV: PPUDPPacket) cdecl; external SDLNet_LibName;
procedure SDLNet_FreeSocketSet(set_: TSDLNet_SocketSet) cdecl; external SDLNet_LibName;
function SDLNet_GetError(): PAnsiChar; cdecl; external SDLNet_LibName;
function SDLNet_GetLocalAddresses(addresses: PIPaddress; maxcount: cint): cint cdecl; external SDLNet_LibName;
function SDLNet_Init(): cint cdecl; external SDLNet_LibName;
function SDLNet_Linked_Version: PSDL_Version cdecl; external SDLNet_LibName;
procedure SDLNet_Quit() cdecl; external SDLNet_LibName;
function SDLNet_ResizePacket(packet: PUDPPacket; newsize: cint): cint cdecl; external SDLNet_LibName;
function SDLNet_ResolveHost(address: PIPaddress; const host: PAnsiChar; port: cuint16): cint cdecl; external SDLNet_LibName;
function SDLNet_ResolveIP(const ip: PIPaddress): PAnsiChar cdecl; external SDLNet_LibName;
procedure SDLNet_SetError(const fmt: PAnsiChar; args: array of const); cdecl; external SDLNet_LibName;
function SDLNet_SocketReady(sock: TSDLNet_GenericSocket): cint;
function SDLNet_TCP_Accept(server: TTCPSocket): TTCPSocket cdecl; external SDLNet_LibName;
procedure SDLNet_TCP_Close(sock: TTCPSocket) cdecl; external SDLNet_LibName;
function SDLNet_TCP_GetPeerAddress(sock: TTCPSocket): PIPaddress cdecl; external SDLNet_LibName;
function SDLNet_TCP_Open(ip: PIPaddress): TTCPSocket cdecl; external SDLNet_LibName;
function SDLNet_TCP_Recv(sock: TTCPSocket; data: Pointer; maxlen: cint): cint cdecl; external SDLNet_LibName;
function SDLNet_TCP_Send(sock: TTCPSocket; const data: Pointer; len: cint): cint cdecl; external SDLNet_LibName;
function SDLNet_UDP_Bind(sock: TUDPSocket; channel: cint; const address: PIPaddress): cint cdecl; external SDLNet_LibName;
procedure SDLNet_UDP_Close(sock: TUDPSocket) cdecl; external SDLNet_LibName;
function SDLNet_UDP_GetPeerAddress(sock: TUDPSocket; channel: cint): PIPaddress cdecl; external SDLNet_LibName;
function SDLNet_UDP_Open(port: cuint16): TUDPSocket cdecl; external SDLNet_LibName;
function SDLNet_UDP_Recv(sock: TUDPSocket; packet: PUDPPacket): cint cdecl; external SDLNet_LibName;
function SDLNet_UDP_RecvV(sock: TUDPSocket; packets: PPUDPPacket): cint cdecl; external SDLNet_LibName;
function SDLNet_UDP_Send(sock: TUDPSocket; channel: cint; packet: PUDPPacket): cint cdecl; external SDLNet_LibName;
function SDLNet_UDP_SendV(sock: TUDPSocket; packets: PPUDPPacket; npackets: cint): cint cdecl; external SDLNet_LibName;
procedure SDLNet_UDP_SetPacketLoss(sock: TUDPSocket; percent: cint) cdecl; external SDLNet_LibName;
procedure SDLNet_UDP_Unbind(sock: TUDPSocket; channel: cint) cdecl; external SDLNet_LibName;
procedure SDL_NET_VERSION(Out X: TSDL_Version);

Types

PIPaddress = ˆTIPaddress;
ppcuint8 = ˆpcuint8;
PPIPaddress = ˆPIPaddress;
PPSDLNet_GenericSocket = ˆPSDLNet_GenericSocket;
PPSDLNet_SocketSet = ˆPSDLNet_SocketSet;
PPSDLNet_Version = ˆPSDLNet_Version;
PPUDPPacket = ˆPUDPPacket;
PPUDPSocket = ˆPUDPSocket;
PPUInt8Array = ˆPUInt8Array;
PSDLNet_GenericSocket = ˆTSDLNet_GenericSocket;
PSDLNet_SocketSet = ˆTSDLNet_SocketSet;
PSDLNet_Version = ˆTSDLNet_Version;
PUDPPacket = ˆTUDPPacket;
PUDPSocket = ˆTUDPSocket;
PUInt8Array = ˆTUInt8Array;
TSDLNet_Version = TSDL_Version;
TTCPSocket = ˆ_TCPSocket;
TUInt8Array = array [0..MAXINT shr 1] of cuint8;

Constants

INADDR_ANY = $00000000;
INADDR_BROADCAST = $FFFFFFFF;
INADDR_LOOPBACK = $7f000001;
INADDR_NONE = $FFFFFFFF;
SDLNET_MAX_UDPADDRESSES = 4;
SDLNET_MAX_UDPCHANNELS = 32;
SDL_NET_MAJOR_VERSION = 2;
SDL_NET_MINOR_VERSION = 0;
SDL_NET_PATCHLEVEL = 0;

Description

Functions and Procedures

function SDLNet_AddSocket(set_: TSDLNet_SocketSet; sock: TSDLNet_GenericSocket): cint cdecl; external SDLNet_LibName;

Add a socket to a set of sockets to be checked for available data *

function SDLNet_AllocPacket(size: cint): PUDPPacket cdecl; external SDLNet_LibName;

Allocate/resize/free a single UDP packet 'size' bytes long. The new packet is returned, or NULL if the function ran out of memory.

function SDLNet_AllocPacketV(howmany: cint; size: cint): PPUDPPacket cdecl; external SDLNet_LibName;

Allocate/Free a UDP packet vector (array of packets) of 'howmany' packets, each 'size' bytes long. A pointer to the first packet in the array is returned, or NULL if the function ran out of memory.

function SDLNet_AllocSocketSet(maxsockets: cint): TSDLNet_GenericSocket cdecl; external SDLNet_LibName;

Allocate a socket set for use with SDLNet_CheckSockets() This returns a socket set for up to 'maxsockets' sockets, or NULL if the function ran out of memory.

function SDLNet_CheckSockets(set_: TSDLNet_SocketSet; timeout: cuint32): cint cdecl; external SDLNet_LibName;

This function checks to see if data is available for reading on the given set of sockets. If 'timeout' is 0, it performs a quick poll, otherwise the function returns when either data is available for reading, or the timeout in milliseconds has elapsed, which ever occurs first. This function returns the number of sockets ready for reading, or -1 if there was an error with the select() system call.

function SDLNet_DelSocket(set_: TSDLNet_SocketSet; sock: TSDLNet_GenericSocket): cint cdecl; external SDLNet_LibName;

Remove a socket from a set of sockets to be checked for available data *

procedure SDLNet_FreePacket(packet: PUDPPacket) cdecl; external SDLNet_LibName;
 
procedure SDLNet_FreePacketV(packetV: PPUDPPacket) cdecl; external SDLNet_LibName;
 
procedure SDLNet_FreeSocketSet(set_: TSDLNet_SocketSet) cdecl; external SDLNet_LibName;

Free a set of sockets allocated by SDL_NetAllocSocketSet() *

function SDLNet_GetError(): PAnsiChar; cdecl; external SDLNet_LibName;
 
function SDLNet_GetLocalAddresses(addresses: PIPaddress; maxcount: cint): cint cdecl; external SDLNet_LibName;

Get the addresses of network interfaces on this system. This returns the number of addresses saved in 'addresses'

function SDLNet_Init(): cint cdecl; external SDLNet_LibName;

Initialize/Cleanup the network API SDL must be initialized before calls to functions in this library, because this library uses utility functions from the SDL library.

function SDLNet_Linked_Version: PSDL_Version cdecl; external SDLNet_LibName;

This function gets the version of the dynamically linked SDL_net library. it should NOT be used to fill a version structure, instead you should use the SDL_NET_VERSION() macro.

procedure SDLNet_Quit() cdecl; external SDLNet_LibName;
 
function SDLNet_ResizePacket(packet: PUDPPacket; newsize: cint): cint cdecl; external SDLNet_LibName;
 
function SDLNet_ResolveHost(address: PIPaddress; const host: PAnsiChar; port: cuint16): cint cdecl; external SDLNet_LibName;
 
function SDLNet_ResolveIP(const ip: PIPaddress): PAnsiChar cdecl; external SDLNet_LibName;

Resolve an ip address to a host name in canonical form. If the ip couldn't be resolved, this function returns NULL, otherwise a pointer to a static buffer containing the hostname is returned. Note that this function is not thread-safe.

procedure SDLNet_SetError(const fmt: PAnsiChar; args: array of const); cdecl; external SDLNet_LibName;
 
function SDLNet_SocketReady(sock: TSDLNet_GenericSocket): cint;

After calling SDLNet_CheckSockets(), you can use this function on a socket that was in the socket set, to find out if data is available for reading.

function SDLNet_TCP_Accept(server: TTCPSocket): TTCPSocket cdecl; external SDLNet_LibName;

Accept an incoming connection on the given server socket. The newly created socket is returned, or NULL if there was an error.

procedure SDLNet_TCP_Close(sock: TTCPSocket) cdecl; external SDLNet_LibName;

Close a TCP network socket *

function SDLNet_TCP_GetPeerAddress(sock: TTCPSocket): PIPaddress cdecl; external SDLNet_LibName;

Get the IP address of the remote system associated with the socket. If the socket is a server socket, this function returns NULL.

function SDLNet_TCP_Open(ip: PIPaddress): TTCPSocket cdecl; external SDLNet_LibName;

Open a TCP network socket If ip.host is INADDR_NONE or INADDR_ANY, this creates a local server socket on the given port, otherwise a TCP connection to the remote host and port is attempted. The address passed in should already be swapped to network byte order (addresses returned from SDLNet_ResolveHost() are already in the correct form). The newly created socket is returned, or NULL if there was an error.

function SDLNet_TCP_Recv(sock: TTCPSocket; data: Pointer; maxlen: cint): cint cdecl; external SDLNet_LibName;

Receive up to 'maxlen' bytes of data over the non-server socket 'sock', and store them in the buffer pointed to by 'data'. This function returns the actual amount of data received. If the return value is less than or equal to zero, then either the remote connection was closed, or an unknown socket error occurred.

function SDLNet_TCP_Send(sock: TTCPSocket; const data: Pointer; len: cint): cint cdecl; external SDLNet_LibName;

Send 'len' bytes of 'data' over the non-server socket 'sock' This function returns the actual amount of data sent. If the return value is less than the amount of data sent, then either the remote connection was closed, or an unknown socket error occurred.

function SDLNet_UDP_Bind(sock: TUDPSocket; channel: cint; const address: PIPaddress): cint cdecl; external SDLNet_LibName;

Bind the address 'address' to the requested channel on the UDP socket. If the channel is -1, then the first unbound channel that has not yet been bound to the maximum number of addresses will be bound with the given address as it's primary address. If the channel is already bound, this new address will be added to the list of valid source addresses for packets arriving on the channel. If the channel is not already bound, then the address becomes the primary address, to which all outbound packets on the channel are sent. This function returns the channel which was bound, or -1 on error.

procedure SDLNet_UDP_Close(sock: TUDPSocket) cdecl; external SDLNet_LibName;

Close a UDP network socket *

function SDLNet_UDP_GetPeerAddress(sock: TUDPSocket; channel: cint): PIPaddress cdecl; external SDLNet_LibName;

Get the primary IP address of the remote system associated with the socket and channel. If the channel is -1, then the primary IP port of the UDP socket is returned – this is only meaningful for sockets opened with a specific port. If the channel is not bound and not -1, this function returns NULL.

function SDLNet_UDP_Open(port: cuint16): TUDPSocket cdecl; external SDLNet_LibName;

Open a UDP network socket If 'port' is non-zero, the UDP socket is bound to a local port. The 'port' should be given in native byte order, but is used internally in network (big endian) byte order, in addresses, etc. This allows other systems to send to this socket via a known port.

function SDLNet_UDP_Recv(sock: TUDPSocket; packet: PUDPPacket): cint cdecl; external SDLNet_LibName;

Receive a single packet from the UDP socket. The returned packet contains the source address and the channel it arrived on. If it did not arrive on a bound channel, the the channel will be set to -1. The channels are checked in highest to lowest order, so if an address is bound to multiple channels, the highest channel with the source address bound will be returned. This function returns the number of packets read from the network, or -1 on error. This function does not block, so can return 0 packets pending.

function SDLNet_UDP_RecvV(sock: TUDPSocket; packets: PPUDPPacket): cint cdecl; external SDLNet_LibName;

Receive a vector of pending packets from the UDP socket. The returned packets contain the source address and the channel they arrived on. If they did not arrive on a bound channel, the the channel will be set to -1. The channels are checked in highest to lowest order, so if an address is bound to multiple channels, the highest channel with the source address bound will be returned. This function returns the number of packets read from the network, or -1 on error. This function does not block, so can return 0 packets pending.

function SDLNet_UDP_Send(sock: TUDPSocket; channel: cint; packet: PUDPPacket): cint cdecl; external SDLNet_LibName;

Send a single packet to the specified channel. If the channel specified in the packet is -1, the packet will be sent to the address in the 'src' member of the packet. The packet will be updated with the status of the packet after it has been sent. This function returns 1 if the packet was sent, or 0 on error.

NOTE: The maximum size of the packet is limited by the MTU (Maximum Transfer Unit) of the transport medium. It can be as low as 250 bytes for some PPP links, and as high as 1500 bytes for ethernet.

function SDLNet_UDP_SendV(sock: TUDPSocket; packets: PPUDPPacket; npackets: cint): cint cdecl; external SDLNet_LibName;

Send a vector of packets to the the channels specified within the packet. If the channel specified in the packet is -1, the packet will be sent to the address in the 'src' member of the packet. Each packet will be updated with the status of the packet after it has been sent, -1 if the packet send failed. This function returns the number of packets sent.

procedure SDLNet_UDP_SetPacketLoss(sock: TUDPSocket; percent: cint) cdecl; external SDLNet_LibName;

Set the percentage of simulated packet loss for packets sent on the socket. *

procedure SDLNet_UDP_Unbind(sock: TUDPSocket; channel: cint) cdecl; external SDLNet_LibName;

Unbind all addresses from the given channel *

procedure SDL_NET_VERSION(Out X: TSDL_Version);

This macro can be used to fill a version structure with the compile-time version of the SDL_net library.

Types

PIPaddress = ˆTIPaddress;
 
ppcuint8 = ˆpcuint8;
 
PPIPaddress = ˆPIPaddress;
 
PPSDLNet_GenericSocket = ˆPSDLNet_GenericSocket;

Any network socket can be safely cast to this socket type *

PPSDLNet_SocketSet = ˆPSDLNet_SocketSet;
 
PPSDLNet_Version = ˆPSDLNet_Version;
 
PPUDPPacket = ˆPUDPPacket;
 
PPUDPSocket = ˆPUDPSocket;
 
PPUInt8Array = ˆPUInt8Array;

Data types for all compilers

PSDLNet_GenericSocket = ˆTSDLNet_GenericSocket;
 
PSDLNet_SocketSet = ˆTSDLNet_SocketSet;
 
PSDLNet_Version = ˆTSDLNet_Version;
 
PUDPPacket = ˆTUDPPacket;
 
PUDPSocket = ˆTUDPSocket;
 
PUInt8Array = ˆTUInt8Array;
 
TSDLNet_Version = TSDL_Version;
 
TTCPSocket = ˆ_TCPSocket;
 
TUInt8Array = array [0..MAXINT shr 1] of cuint8;
 

Constants

INADDR_ANY = $00000000;

Resolve a host name and port to an IP address in network form. If the function succeeds, it will return 0. If the host couldn't be resolved, the host portion of the returned address will be INADDR_NONE, and the function will return -1. If 'host' is NULL, the resolved host will be set to INADDR_ANY.

INADDR_BROADCAST = $FFFFFFFF;
 
INADDR_LOOPBACK = $7f000001;
 
INADDR_NONE = $FFFFFFFF;
 
SDLNET_MAX_UDPADDRESSES = 4;

The maximum addresses bound to a single UDP socket channel *

SDLNET_MAX_UDPCHANNELS = 32;

The maximum channels on a a UDP socket *

SDL_NET_MAJOR_VERSION = 2;

Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *

SDL_NET_MINOR_VERSION = 0;
 
SDL_NET_PATCHLEVEL = 0;
 

Generated by PasDoc 0.16.0.