Networking

Networking

Description

The networking code of SwinGame is used for TCP and UDP connections to and from multiple clients.

Accept TCPConnection

Accepts an incomming connection from another client. Returns the amount of new connections that have been accepted.

  • Accept TCPConnection () : Longint [show]

    Accepts an incomming connection from another client. Returns the amount of new connections that have been accepted.

    Returns:
    Longint :
    Signatures by Language:
    C/C++: int32_t accept_tcpconnection();
    Pascal: function AcceptTCPConnection(): Longint;

Broadcast TCPMessage

Broadcasts a message through all open connections.

  • Broadcast TCPMessage (aMsg) [show]

    Broadcasts a message through all open connections.

    Parameters:
    aMsg : String
    The message to be sent
    Signatures by Language:
    C/C++: void broadcast_tcpmessage(const char *aMsg);
    Pascal: procedure BroadcastTCPMessage(aMsg: String);

Broadcast UDPMessage

Sends a UDP packet to All connections with the message.

  • Broadcast UDPMessage (aMsg) [show]

    Sends a UDP packet to All connections with the message.

    Parameters:
    aMsg : String
    The message to be sent
    Signatures by Language:
    C/C++: void broadcast_udpmessage(const char *aMsg);
    Pascal: procedure BroadcastUDPMessage(aMsg: String);

Clear Message Queue

Clears the Message Queue

  • Clear Message Queue (aConnection) [show]

    Clears the Message Queue

    Parameters:
    aConnection : Connection
    Signatures by Language:
    C/C++: void clear_message_queue(connection aConnection);
    Pascal: procedure ClearMessageQueue(aConnection: Connection);

Close All Connections

Closes All TCP Receiver Sockets


Close All Sockets

Closes all sockets that have been created.


Close All TCPHost Sockets

Closes All TCP Host Sockets


Close All UDPSockets

Closes All UDP Listener Sockets


Close Connection

Closes the specified Socket, removed it from the Socket Array, and removes the identifier from the NamedIndexCollection. Refers to TCP Receiver Sockets

  • Close Connection (var aConnection) : Boolean [show]

    Closes the specified Socket, removed it from the Socket Array, and removes the identifier from the NamedIndexCollection. Refers to TCP Receiver Sockets

    Parameters:
    aConnection : Connection
    The Connection to close
    Returns:
    Boolean :
    Signatures by Language:
    C/C++: bool close_connection(connection *aConnection);
    C++: bool close_connection(connection &aConnection);
    Pascal: function CloseConnection(var aConnection: Connection): Boolean;

Close TCPHost Socket

Closes the specified Socket, removed it from the Socket Array, and removes the identifier from the NamedIndexCollection. Refers to TCP Host Sockets

  • Close TCPHost Socket (aPort) : Boolean [show]

    Closes the specified Socket, removed it from the Socket Array, and removes the identifier from the NamedIndexCollection. Refers to TCP Host Sockets

    Parameters:
    aPort : Longint
    The identifier of the Host Socket.
    Returns:
    Boolean :
    Signatures by Language:
    C/C++: bool close_tcphost_socket(int32_t aPort);
    Pascal: function CloseTCPHostSocket(aPort: Longint): Boolean;

Close UDPSocket

Closes the specified Socket, removed it from the Socket Array, and removes the identifier from the NamedIndexCollection. Refers to UDP Listener Sockets

  • Close UDPSocket (aPort) : Boolean [show]

    Closes the specified Socket, removed it from the Socket Array, and removes the identifier from the NamedIndexCollection. Refers to UDP Listener Sockets

    Parameters:
    aPort : Longint
    The identifier of the Host Socket.
    Returns:
    Boolean :
    Signatures by Language:
    C/C++: bool close_udpsocket(int32_t aPort);
    Pascal: function CloseUDPSocket(aPort: Longint): Boolean;

Connection Count

Returns the count of Active Connections

  • Connection Count () : Longint [show]

    Returns the count of Active Connections

    Returns:
    Longint :
    Signatures by Language:
    C/C++: int32_t connection_count();
    Pascal: function ConnectionCount(): Longint;

Connection IP

Gets the Decimal IP of the destination for the connection

  • Connection IP (aConnection) : Longword [show]

    Gets the Decimal IP of the destination for the connection

    Parameters:
    aConnection : Connection
    The connection to extract data from
    Returns:
    Longword :
    Signatures by Language:
    C/C++: uint32_t connection_ip(connection aConnection);
    Pascal: function ConnectionIP(aConnection: Connection): Longword;

Connection Port

Gets the Port of the destination for the connectiom

  • Connection Port (aConnection) : Longint [show]

    Gets the Port of the destination for the connectiom

    Parameters:
    aConnection : Connection
    The connection to extract data from
    Returns:
    Longint :
    Signatures by Language:
    C/C++: int32_t connection_port(connection aConnection);
    Pascal: function ConnectionPort(aConnection: Connection): Longint;

Connection Queue Size

Returns the size of the New Connection List

  • Connection Queue Size () : Longint [show]

    Returns the size of the New Connection List

    Returns:
    Longint :
    Signatures by Language:
    C/C++: int32_t connection_queue_size();
    Pascal: function ConnectionQueueSize(): Longint;

Create TCPConnection

Opens a connection to a peer using the IP and port Creates a Socket for the purpose of two way messages. Returns a new connection if successful or nil if failed.

  • Create TCPConnection (aIP, aPort) : Connection [show]

    Opens a connection to a peer using the IP and port Creates a Socket for the purpose of two way messages. Returns a new connection if successful or nil if failed.

    Parameters:
    aIP : String
    The IP Address of the host
    aPort : Longint
    The port the host is listening to connections on
    Returns:
    Connection :
    Signatures by Language:
    C/C++: connection create_tcpconnection_to_host(const char *aIP, int32_t aPort);
    C++: connection create_tcpconnection(const char *aIP, int32_t aPort);
    Pascal: function CreateTCPConnection(aIP: String; aPort: Longint): Connection;

Create TCPHost

Creates a socket that listens for connections based on the port given. Returns true if success or false if the binding failed. Uses TCP.

  • Create TCPHost (aPort) : Boolean [show]

    Creates a socket that listens for connections based on the port given. Returns true if success or false if the binding failed. Uses TCP.

    Parameters:
    aPort : Longint
    The port to bind the socket to.
    Returns:
    Boolean :
    Signatures by Language:
    C/C++: bool create_tcphost(int32_t aPort);
    Pascal: function CreateTCPHost(aPort: Longint): Boolean;

Create UDPConnection

Creates the connection and sets the ip and port values. Creates a socket if there is no socket attached to the specified port. this socket can be used to send and receive messages. Returns the connection if this has been successful, or will return nil on failure.

  • Create UDPConnection (aDestIP, aDestPort, aInPort) : Connection [show]

    Creates the connection and sets the ip and port values. Creates a socket if there is no socket attached to the specified port. this socket can be used to send and receive messages. Returns the connection if this has been successful, or will return nil on failure.

    Parameters:
    aDestIP : String
    The destination IP
    aDestPort : Longint
    The Destination Port
    aInPort : Longint
    The port to receive messages
    Returns:
    Connection :
    Signatures by Language:
    C/C++: connection create_udpconnection(const char *aDestIP, int32_t aDestPort, int32_t aInPort);
    Pascal: function CreateUDPConnection(aDestIP: String; aDestPort: Longint; aInPort: Longint): Connection;

Create UDPHost

Creates a socket that listens for connections based on the port given. Returns the index of the Socket in the socket array.

  • Create UDPHost (aPort) : Longint [show]

    Creates a socket that listens for connections based on the port given. Returns the index of the Socket in the socket array.

    Parameters:
    aPort : Longint
    The port to bind the socket to.
    Returns:
    Longint :
    Signatures by Language:
    C/C++: int32_t create_udphost(int32_t aPort);
    Pascal: function CreateUDPHost(aPort: Longint): Longint;

Dec To Hex

Converts an Integer to a Hex value and returns it as a string.

  • Dec To Hex (aDec) : String [show]

    Converts an Integer to a Hex value and returns it as a string.

    Parameters:
    aDec : Longword
    The Integer
    Returns:
    String :
    Signatures by Language:
    C/C++: void dec_to_hex(uint32_t aDec, char *result);
    Pascal: function DecToHex(aDec: Longword): String;

Enqueue Message

Queues a message to the end of the Message Queue

  • Enqueue Message (aMsg, aConnection) [show]

    Queues a message to the end of the Message Queue

    Parameters:
    aMsg : String
    The message Sent
    aConnection : Connection
    The connection to enqueue the message into
    Signatures by Language:
    C/C++: void enqueue_message(const char *aMsg, connection aConnection);
    Pascal: procedure EnqueueMessage(aMsg: String; aConnection: Connection);

Enqueue New Connection

Adds a connection to the list of new connections. This is called by the Accept connection in TCP and Receive message in UDP (if the message has been sent by a new connection). This is used in conjunction with Fetch connection, that will pop the new connection out of the list.

  • Enqueue New Connection (aConnection) [show]

    Adds a connection to the list of new connections. This is called by the Accept connection in TCP and Receive message in UDP (if the message has been sent by a new connection). This is used in conjunction with Fetch connection, that will pop the new connection out of the list.

    Parameters:
    aConnection : Connection
    The new connection to add to the list
    Signatures by Language:
    C/C++: void enqueue_new_connection(connection aConnection);
    Pascal: procedure EnqueueNewConnection(aConnection: Connection);

Fetch Connection

Removes the top connection from the New connection queue and returns it.

  • Fetch Connection () : Connection [show]

    Removes the top connection from the New connection queue and returns it.

    Returns:
    Connection :
    Signatures by Language:
    C/C++: connection fetch_connection();
    Pascal: function FetchConnection(): Connection;

Free Connection

An internal function used to close the specified Socket. Call CloseConnection instead.

  • Free Connection (var aConnection) [show]

    An internal function used to close the specified Socket. Call CloseConnection instead.

    Parameters:
    aConnection : Connection
    The Connection to close
    Signatures by Language:
    C/C++: void free_connection(connection *aConnection);
    C++: void free_connection(connection &aConnection);
    Pascal: procedure FreeConnection(var aConnection: Connection);

Hex Str To IPv4

Converts a Hex String to an IPV4 Address (0.0.0.0)

  • Hex Str To IPv4 (aHex) : String [show]

    Converts a Hex String to an IPV4 Address (0.0.0.0)

    Parameters:
    aHex : String
    The Hex String
    Returns:
    String :
    Signatures by Language:
    C/C++: void hex_str_to_ipv4(const char *aHex, char *result);
    Pascal: function HexStrToIPv4(aHex: String): String;

Hex To Dec String

Converts a Hex String to a Decimal Value as a String.

  • Hex To Dec String (aHex) : String [show]

    Converts a Hex String to a Decimal Value as a String.

    Parameters:
    aHex : String
    The Hex String
    Returns:
    String :
    Signatures by Language:
    C/C++: void hex_to_dec_string(const char *aHex, char *result);
    Pascal: function HexToDecString(aHex: String): String;

IPv4 To Dec

Converts an IP to a decimal value

  • IPv4 To Dec (aIP) : Longword [show]

    Converts an IP to a decimal value

    Parameters:
    aIP : String
    The IP
    Returns:
    Longword :
    Signatures by Language:
    C/C++: uint32_t ipv4_to_dec(const char *aIP);
    Pascal: function IPv4ToDec(aIP: String): Longword;

Message Count

Gets the Size of the Message Queue

  • Message Count (aConnection) : Longint [show]

    Gets the Size of the Message Queue

    Parameters:
    aConnection : Connection
    Returns:
    Longint :
    Signatures by Language:
    C/C++: int32_t message_count(connection aConnection);
    Pascal: function MessageCount(aConnection: Connection): Longint;

My IP

Returns the caller's IP.

  • My IP () : String [show]

    Returns the caller's IP.

    Returns:
    String :
    Signatures by Language:
    C/C++: void my_ip(char *result);
    Pascal: function MyIP(): String;

Read Last Message

Dequeues the Last (Newest) Message

  • Read Last Message (aConnection) : String [show]

    Dequeues the Last (Newest) Message

    Parameters:
    aConnection : Connection
    The connection to extract data from
    Returns:
    String :
    Signatures by Language:
    C/C++: void read_last_message(connection aConnection, char *result);
    Pascal: function ReadLastMessage(aConnection: Connection): String;

Read Message

Dequeues the Top (Oldest) Message

  • Read Message (aConnection) : String [show]

    Dequeues the Top (Oldest) Message

    Parameters:
    aConnection : Connection
    The connection to extract data from
    Returns:
    String :
    Signatures by Language:
    C/C++: void read_message(connection aConnection, char *result);
    Pascal: function ReadMessage(aConnection: Connection): String;

Release All Connections

Releases All resources used by the Networking code.

  • Release All Connections () [show]

    Releases All resources used by the Networking code.


Retreive Connection

Retrieves the connection at the specified index

  • Retreive Connection (aConnectionAt) : Connection [show]

    Retrieves the connection at the specified index

    Parameters:
    aConnectionAt : Longint
    The index of the connection
    Returns:
    Connection :
    Signatures by Language:
    C/C++: connection retreive_connection(int32_t aConnectionAt);
    Pascal: function RetreiveConnection(aConnectionAt: Longint): Connection;

Send TCPMessage

Sends the message to the specified client, attached to the socket Retuns the connection if the message fails to send so that it may be closed. Returns nil if the message has been sent successfully.

  • Send TCPMessage (aMsg, aConnection) : Connection [show]

    Sends the message to the specified client, attached to the socket Retuns the connection if the message fails to send so that it may be closed. Returns nil if the message has been sent successfully.

    Parameters:
    aMsg : String
    The message to be sent
    aConnection : Connection
    Send the message through this connection's socket.
    Returns:
    Connection :
    Signatures by Language:
    C/C++: connection send_tcpmessage(const char *aMsg, connection aConnection);
    Pascal: function SendTCPMessage(aMsg: String; aConnection: Connection): Connection;

Send UDPMessage

Sends a UDP packet to the port and ip specified in the connection with the message.

  • Send UDPMessage (aMsg, aConnection) : Boolean [show]

    Sends a UDP packet to the port and ip specified in the connection with the message.

    Parameters:
    aMsg : String
    The message to be sent
    aConnection : Connection
    Send the Message through this connection's Socket.
    Returns:
    Boolean :
    Signatures by Language:
    C/C++: bool send_udpmessage(const char *aMsg, connection aConnection);
    Pascal: function SendUDPMessage(aMsg: String; aConnection: Connection): Boolean;

TCPMessage Received

Checks if a message has been received. If a message has been received, It will automatically add it to the message queue, with the message, source's IP and the port it received the message on. Returns true if a new message has been received.

  • TCPMessage Received () : Boolean [show]

    Checks if a message has been received. If a message has been received, It will automatically add it to the message queue, with the message, source's IP and the port it received the message on. Returns true if a new message has been received.

    Returns:
    Boolean :
    Signatures by Language:
    C/C++: bool tcpmessage_received();
    Pascal: function TCPMessageReceived(): Boolean;

UDPMessage Received

Checks all UDP listening sockets to see if a packet has been received. If a packet has been received, it will Enqueue the message into the message queue. This will set the message, sender's address and sender's port. it will return true if a message has been received or false if there has been no message.

  • UDPMessage Received () : Boolean [show]

    Checks all UDP listening sockets to see if a packet has been received. If a packet has been received, it will Enqueue the message into the message queue. This will set the message, sender's address and sender's port. it will return true if a message has been received or false if there has been no message.

    Returns:
    Boolean :
    Signatures by Language:
    C/C++: bool udpmessage_received();
    Pascal: function UDPMessageReceived(): Boolean;