![]() |
C-chat
|
API for sockets. More...
Go to the source code of this file.
Classes | |
struct | Socket |
Information of a socket. More... | |
Typedefs | |
typedef struct Socket | Socket |
Functions | |
Socket | createClientSocket (const char *ipAddress, const char *port) |
Creates a socket meant to be used to connect to a server socket and initialize a connection with the server. More... | |
Socket | createServerSocket (const char *port) |
Creates a socket meant to receive connection from clients sockets. More... | |
Socket | acceptClient (Socket serverSocket) |
Waits for a client to connect to the given server socket. Returns the socket for the connected client. More... | |
int | receiveFrom (Socket clientSocket, char *buffer, unsigned int bufferSize) |
Receives through from the given socket. More... | |
int | sendTo (Socket clientSocket, const char *buffer, unsigned int bufferSize) |
Sends data through the given socket. More... | |
void | closeSocket (Socket *socket) |
Closes the given socket. More... | |
void | cleanUp () |
Performs any required resources cleanup. Must be called once all sockets usage is finished. | |
API for sockets.
A general API to manipulate sockets.
Waits for a client to connect to the given server socket. Returns the socket for the connected client.
serverSocket | The server socket |
void closeSocket | ( | Socket * | socket | ) |
Closes the given socket.
socket | The a pointer to the socket to close |
Socket createClientSocket | ( | const char * | ipAddress, |
const char * | port | ||
) |
Creates a socket meant to be used to connect to a server socket and initialize a connection with the server.
ipAddress | The IP address of the server to connect to |
port | The port to connect on |
Socket createServerSocket | ( | const char * | port | ) |
Creates a socket meant to receive connection from clients sockets.
port | The port the server must listen on |
int receiveFrom | ( | Socket | clientSocket, |
char * | buffer, | ||
unsigned int | bufferSize | ||
) |
Receives through from the given socket.
clientSocket | The socket to receive data from |
buffer | A buffer to store received data in |
bufferSize | The maximum size of data to receive |
int sendTo | ( | Socket | clientSocket, |
const char * | buffer, | ||
unsigned int | bufferSize | ||
) |
Sends data through the given socket.
clientSocket | The socket to send a message through |
buffer | A buffer containing to data to send |
bufferSize | The size of the data to send |