3D-ICE 3.0.0
Data Structures | Typedefs | Functions
network_socket.h File Reference
#include <netinet/in.h>
#include "types.h"
#include "string_t.h"
#include "network_message.h"

Go to the source code of this file.

Data Structures

struct  Socket_t
 Structure used to set up and use network connections. More...
 

Typedefs

typedef struct Socket_t Socket_t
 

Functions

void socket_init (Socket_t *socket)
 
Error_t open_client_socket (Socket_t *csocket)
 
Error_t open_server_socket (Socket_t *ssocket, PortNumber_t port_number)
 
Error_t connect_client_to_server (Socket_t *csocket, String_t host_name, PortNumber_t port_number)
 
Error_t wait_for_client (Socket_t *ssocket, Socket_t *client)
 
Error_t send_message_to_socket (Socket_t *socket, NetworkMessage_t *message)
 
Error_t receive_message_from_socket (Socket_t *socket, NetworkMessage_t *message)
 
Error_t socket_close (Socket_t *socket)
 

Typedef Documentation

◆ Socket_t

typedef struct Socket_t Socket_t

Definition of the type Socket_t

Definition at line 87 of file network_socket.h.

Function Documentation

◆ connect_client_to_server()

Error_t connect_client_to_server ( Socket_t csocket,
String_t  host_name,
PortNumber_t  port_number 
)

Connects the client to a server

Prepares the address of the server and establish the connection. The server side must be waiting for a connection. On error, the socket is closed.

Parameters
csocketthe address of the ClientSocket to initialize
host_namethe ip address of the server (as dotted string)
port_numberthe port number of the server
Returns
TDICE_SUCCESS if the connection succeeded
TDICE_FAILURE if the connections fails. A message will be printed on standard error

Definition at line 124 of file network_socket.c.

◆ open_client_socket()

Error_t open_client_socket ( Socket_t csocket)

Open a socket for the client side

Parameters
csocketthe address of the Socket to open
Returns
TDICE_SUCCESS if the opening succeeded
TDICE_FAILURE if the opening fails. A message will be printed on standard error

Definition at line 65 of file network_socket.c.

◆ open_server_socket()

Error_t open_server_socket ( Socket_t ssocket,
PortNumber_t  port_number 
)

Open a socket for the server side

The function creates the socket. Then it binds the socket to the port_numebr over any kind of address. It finally enables the listening.

Parameters
ssocketthe address of the Socket to open
port_numberthe port number of the server
Returns
TDICE_SUCCESS if the opening succeeded
TDICE_FAILURE if the opening fails. A message will be printed on standard error

Definition at line 81 of file network_socket.c.

◆ receive_message_from_socket()

Error_t receive_message_from_socket ( Socket_t socket,
NetworkMessage_t message 
)

Receive a text message from a socket

Parameters
socketthe socket where the message will be received
messagethe address of message to receive
Returns
TDICE_SUCCESS if the operation succeeded
TDICE_FAILURE if the operation fails. A message will be printed on standard error

Definition at line 249 of file network_socket.c.

◆ send_message_to_socket()

Error_t send_message_to_socket ( Socket_t socket,
NetworkMessage_t message 
)

Sends a message to a socket

Parameters
socketthe socket where the message will be sent
messagethe address of message to send
Returns
TDICE_SUCCESS if the operation succeeded
TDICE_FAILURE if the operation fails. A message will be printed on standard error

Definition at line 197 of file network_socket.c.

◆ socket_close()

Error_t socket_close ( Socket_t socket)

Closes a socket

Parameters
socketthe address of the Socket to close
Returns
TDICE_SUCCESS if the closure succeeded
TDICE_FAILURE if the closure fails. A message will be printed on standard error

Definition at line 318 of file network_socket.c.

◆ socket_init()

void socket_init ( Socket_t socket)

Inits the fields of the socket structure with default values

Parameters
socketthe address of the structure to initalize

Definition at line 52 of file network_socket.c.

◆ wait_for_client()

Error_t wait_for_client ( Socket_t ssocket,
Socket_t client 
)

Waits unitl a client sends a connect to the server

Parameters
ssocketthe address of the ServerSocket that will wait
clientthe address of the ClientSocket that will connect_to_server
Returns
TDICE_SUCCESS if the connection with the client succeeded
TDICE_FAILURE if the connection fails. A message will be printed on standard error

Definition at line 162 of file network_socket.c.