Socket Interface

Socket Overview

The socket interface stands as a foundational abstraction provided by operating systems, facilitating inter-process communication over a network. It serves as the backbone of network programming, enabling the creation of distributed applications that seamlessly communicate across various machines.

A socket serves as an endpoint in a network communication between two processes. It empowers processes to exchange data, regardless of whether they reside on the same machine or are distributed across different machines connected via a network.

Types of Sockets

  • Stream Sockets (TCP)

    Stream sockets deliver reliable, connection-oriented communication. They ensure data delivery in the order it was sent, guaranteeing data integrity during transmission. TCP (Transmission Control Protocol) stands out as the most prevalent protocol for stream sockets.

  • Datagram Sockets (UDP)

    Datagram sockets offer an unreliable, connectionless communication channel. They enable processes to dispatch individual data packets, termed datagrams, without necessitating a prior connection. UDP (User Datagram Protocol) often finds use in real-time applications demanding low latency, such as video streaming and online gaming.

Supported Communication Modes

The following modes of socket communication are supported:

  • Blocking - Here the read/write function waits(blocked) till the operation is performed or time out.

  • Non-Blocking - The read/write function returns immediately with appropriate return values.

Application Interface

The below table captures the functions that are to be called from the application layer.

API Functions

Function

Description

rs_socket_tcp_server_open

To open the TCP server socket.

rs_socket_tcp_client_open

To open the TCP client socket.

rs_socket_set_config

To configure the socket interface.

rs_socket_write

To write the data to the TCP socket interface.

rs_socket_read

To read the data from the TCP socket interface.

rs_socket_close

To close the socket interface.

rs_socket_listen

To listen for the incoming socket connection.

rs_socket_accept

To accept a new socket connection.

rs_socket_connect

To connect to the socket.

rs_socket_udp_server_open

To open the UDP server socket.

rs_socket_udp_client_open

To open the UDP client socket.

rs_socket_write_msg

To write the data to the UDP socket interface.

rs_socket_read_msg

To read the data from the UDP socket interface.

rs_socket_tcp_server_close

To close the tcp socket server connection

rs_socket_tcp_conn_close

To close the tcp socket accept connection

rs_socket_udp_server_close

To close the udp socket server connection

rs_socket_udp_conn_close

To close the udp socket accept connection

rs_socket_udp_set_opt

To sets options associated with a socket for UDP

Error Code

  • Every API’s for the Socket returns some success or failure values. Please refer below section,

Implementation Guide

This section explains how to implement the Socket interface using the RAPIDSEA stack, the steps to be followed are

  • Configure the preferred method of RX or TX communication(Blocking / Non-Blocking).

  • Configure the socket interface(Address, Port number and number of connection).

  • Then call the initialize call of the socket interface for the preferred protocol.

  • Perform the read and write functions as required and handle the error codes.

  • Close the Socket interface.

Note:

The configurations are done by loading the provided socket structure(rs_socket_config_t) from the application layer.

Documentation from the relevant header as follows:

Warning

doxygenfile: Cannot find file “rs_socket.h