Tao.Sdl SDK Documentation

SdlNet.SDLNet_TCP_Open Method 

Open a TCP client or server socket

[Visual Basic]
Public Shared Function SDLNet_TCP_Open( _
   ByRef ip As IPaddress _
) As IntPtr
[C#]
public static IntPtr SDLNet_TCP_Open(
   ref IPaddress ip
);

Parameters

ip
This points to the IPaddress that contains the resolved IP address and port number to use.

Return Value

a valid TCPsocket on success, which indicates a successful connection has been established, or a socket has been created that is valid to accept incoming TCP connections. NULL is returned on errors, such as when it's not able to create a socket, or it cannot connect to host and/or port contained in ip.

Remarks

Connect to the host and port contained in ip using a TCP connection. If the host is INADDR_ANY, then only the port number is used, and a socket is created that can be used to later accept incoming TCP connections.

Binds to C-function call in SDL_net.h:

            extern DECLSPEC TCPsocket SDLCALL SDLNet_TCP_Open(IPaddress *ip)
            

Example

            // connect to localhost at port 9999 using TCP (client)
            IPaddress ip;
            TCPsocket tcpsock;
            if(SDLNet_ResolveHost(&ip,"localhost",9999)==-1) {
            printf("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
            exit(1);
            }
            tcpsock=SDLNet_TCP_Open(&ip);
            if(!tcpsock) {
            printf("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
            exit(2);
            }
            
            // create a listening TCP socket on port 9999 (server)
            IPaddress ip;
            TCPsocket tcpsock;
            if(SDLNet_ResolveHost(&ip,NULL,9999)==-1) {
            printf("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
            exit(1);
            }
            tcpsock=SDLNet_TCP_Open(&ip);
            if(!tcpsock) {
            printf("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
            exit(2);
            }
            

See Also

SdlNet Class | Tao.Sdl Namespace | SDLNet_TCP_Accept | SDLNet_TCP_Close | SdlNet.IPaddress | SdlNet.TCPsocket