Specifications

University of Hertfordshire
35
In this chapter, TCP and socket programming is introduced, which used to
transfer message between the server and the client. And the server program is
explained.
7.1 Introduction to TCP Socket Programming
In this project, TCP and socket programming are used to transfer messages between the server and
the client. The following system functions are used for programming, and will be introduced
respectively.
socket
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol)
A socket is a data communications channel. Once two processes are connected through socket, they
can use a socket descriptor to read and write data to the socket. There are several possible domain
types for sockets can be used.
AF_UNIX: UNIX internal protocols
AF_INET: ARPA Internet protocol (used in server program.)
AF_ISO: International Standards Organization protocols
AF_NS: XeroX Network System protocol
AF_INET is the most widely used protocol, and also be used in server program.
The second argument to the socket function is the type of socket, there are several types of sockets:
SOCK_STREAM: Provide a reliable, sequenced, two-way connection (most frequently
used option)
SOCK_DGRAM: Connectionless and unreliable connection (for UDP)
SOCK_RAW: Used for internal network protocol (superuser only)