SocketTCP.h File Reference

#include <SFML/Config.h>
#include <SFML/Network/IPAddress.h>
#include <SFML/Network/Packet.h>
#include <SFML/Network/SocketStatus.h>

Go to the source code of this file.


Typedefs

typedef sfSocketTCP sfSocketTCP
 SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower).

Functions

CSFML_API sfSocketTCPsfSocketTCP_Create ()
 Construct a new TCP socket.
CSFML_API void sfSocketTCP_Destroy (sfSocketTCP *Socket)
 Destroy an existing TCP socket.
CSFML_API sfBool sfSocketTCP_Connect (sfSocketTCP *Socket, unsigned short Port, sfIPAddress HostAddress, float Timeout)
 Connect a TCP socket to another computer on a specified port.
CSFML_API sfBool sfSocketTCP_Listen (sfSocketTCP *Socket, unsigned short Port)
 Listen to a specified port for incoming data or connections.
CSFML_API sfSocketStatus sfSocketTCP_Accept (sfSocketTCP *Socket, sfSocketTCP **Connected, sfIPAddress *Address)
 Wait for a connection (must be listening to a port).
CSFML_API sfSocketStatus sfSocketTCP_Send (sfSocketTCP *Socket, const char *Data, size_t Size)
 Send an array of bytes to the host (must be connected first).
CSFML_API sfSocketStatus sfSocketTCP_Receive (sfSocketTCP *Socket, char *Data, size_t MaxSize, size_t *SizeReceived)
 Receive an array of bytes from the host (must be connected first).
CSFML_API sfSocketStatus sfSocketTCP_SendPacket (sfSocketTCP *Socket, sfPacket *Packet)
 Send a packet of data to the host (must be connected first).
CSFML_API sfSocketStatus sfSocketTCP_ReceivePacket (sfSocketTCP *Socket, sfPacket *Packet)
 Receive a packet from the host (must be connected first).
CSFML_API sfBool sfSocketTCP_IsValid (sfSocketTCP *Socket)
 Check if a socket is in a valid state ; this function can be called any time to check if the socket is OK.

Typedef Documentation

typedef struct sfSocketTCP sfSocketTCP

SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower).

Definition at line 41 of file SocketTCP.h.


Function Documentation

CSFML_API sfSocketStatus sfSocketTCP_Accept ( sfSocketTCP Socket,
sfSocketTCP **  Connected,
sfIPAddress Address 
)

Wait for a connection (must be listening to a port).

This function is blocking, ie. it won't return before a connection has been accepted

Parameters:
Socket : Socket to use for accepting
Connected : Pointer to a socket pointer that will be filled with the connected client
Address : Pointer to an address to fill with client infos
Returns:
Socket status

CSFML_API sfBool sfSocketTCP_Connect ( sfSocketTCP Socket,
unsigned short  Port,
sfIPAddress  HostAddress,
float  Timeout 
)

Connect a TCP socket to another computer on a specified port.

Parameters:
Socket : Socket to use for connecting
Port : Port to use for transfers (warning : ports < 1024 are reserved)
HostAddress : IP Address of the host to connect to
Timeout : Maximum time to wait (0 to use no timeout)
Returns:
sfTrue if operation has been successful

CSFML_API sfSocketTCP* sfSocketTCP_Create (  ) 

Construct a new TCP socket.

Returns:
Pointer to the new socket

CSFML_API void sfSocketTCP_Destroy ( sfSocketTCP Socket  ) 

Destroy an existing TCP socket.

Parameters:
Socket : Socket to destroy

CSFML_API sfBool sfSocketTCP_IsValid ( sfSocketTCP Socket  ) 

Check if a socket is in a valid state ; this function can be called any time to check if the socket is OK.

Parameters:
Socket : Socket to check
Returns:
True if the socket is valid

CSFML_API sfBool sfSocketTCP_Listen ( sfSocketTCP Socket,
unsigned short  Port 
)

Listen to a specified port for incoming data or connections.

Parameters:
Socket : Socket to use for listening
Port : Port to listen to
Returns:
sfTrue if operation has been successful

CSFML_API sfSocketStatus sfSocketTCP_Receive ( sfSocketTCP Socket,
char *  Data,
size_t  MaxSize,
size_t *  SizeReceived 
)

Receive an array of bytes from the host (must be connected first).

Parameters:
Socket : Socket to use for receiving
Data : Pointer to a byte array to fill (make sure it is big enough)
MaxSize : Maximum number of bytes to read
SizeReceived : Number of bytes received
Returns:
Socket status

CSFML_API sfSocketStatus sfSocketTCP_ReceivePacket ( sfSocketTCP Socket,
sfPacket Packet 
)

Receive a packet from the host (must be connected first).

Parameters:
Socket : Socket to use for receiving
Packet : Packet to fill with received data
Returns:
Socket status

CSFML_API sfSocketStatus sfSocketTCP_Send ( sfSocketTCP Socket,
const char *  Data,
size_t  Size 
)

Send an array of bytes to the host (must be connected first).

Parameters:
Socket : Socket to use for sending
Data : Pointer to the bytes to send
Size : Number of bytes to send
Returns:
Socket status

CSFML_API sfSocketStatus sfSocketTCP_SendPacket ( sfSocketTCP Socket,
sfPacket Packet 
)

Send a packet of data to the host (must be connected first).

Parameters:
Socket : Socket to use for sending
Packet : Packet to send
Returns:
Socket status