Specifications

University of Hertfordshire
37
send & recv
#include<sys/types.h>
#include<sys/socket.h>
int send(int socket, void *buf, int buf_len, unsigned int flags);
int recv(int socket, void *message_data, int message_data_len, unsigned int flags);
The send and recv functions are used to send/receive messages to/from a connected socket, which
has been connected to a socket using a call to connect. The second argument, for send function,
pointer to a block or memory where a received message will be stored; for recv function, the
argument message_data contains any data to be transferred. Third argument to send and recv is the
size of the reserved memory block and the message data to be send. The flags argument indicates
operation flags, and it is always zero in this project. (Wall, Watson & Whitis, 1999)
7.2 Explanation of Server Program
The server program creates one permanent socket for listening for service requests; when a client
connects with the server, a temporary socket is created. Each time a client connects to server, a new
temporary socket is opened between the client and the server. The following data are used to create
both permanent socket and the temporary sockets:
struct sockaddr_in sin;
struct sockaddr_in pin;
int sock_descriptor;
int temp_sock_descriptor;
int address_size;
Then, the socket descriptor defined:
sock_descriptor = socket(AF_INET, SOCK_STREAM, 0);
Next, the required fields of the struct sockaddr_in sin are filled:
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;