IPC and Sockets Programs in C in Linux Platform

IPC: Inter Process Communication means exchanging messages or data between processes.
Processes can reside on same machine or in separate machines in a network according to which IPC or Socket is used.

Traditional IPC:
1. Pipes:Only related Processes can communicate as only child can share the file descriptor of parent.
2. Fifo(named pipes): since fifo has name so it can be opened by other processes for read write.

System V IPC:
1.Message Queue
3.Shared Memory

Socket Programming/ Network programming:
Traditional and System V IPC can be used by processes whicce run on the same machine not over the Network.For the Processes that run on different machines "socket" is used. Socket can be thought of extended System V IPC. Socket Can be thought of end point of a communication channel.
Networking Programming generally follow Client Server model. Server runs forever and waits for requests from clients.Client requests for services from server. Server process the request and send to client.Browsers can be thought of http clients that requests for html pages from http/web servers.

In C programming generally Berkeleys Socket APIs are used for socket programming. Other APIS like TLI(Transport Layer Interface of system V) are also available.

Socket System Calls:

Used by Serverer           Used by client
socket()                  Socket()
close()           close()

Server Program:
First step of any network program is to create a socket using socket() system call.And, initialize the server_address with family,IP and Port.
Then created server is bind() with the server_Address and port on which then server listen() for incoming connections from client. Then server
accept() a connection from client and then read()/write() and finally close() the socket.
Client Program:
Client Program also start with creating a socket() and initialization of server socket with family,IP and port.Then connect() with the server and write()/read() and finally close() the socket.

Note:Apart from read() and write() in socket programming send()/recv() with tcp and sendto()/recvfrom() with udp can also be used.

Note :System V IPC ie message queue, semaphore and shared memory can not use read write as they are not implemented by the kernel.
Message Queue uses below API:
Shared Memory Uses below api:
Semaphore uses below api:

System V semaphore are complex so generally they are wrapped around pthread like semaphore functions.

You may like:

Threaded Concurrent echo TCP Server Code in C in Linux Platform

Concurrent Server handling Multiple Clients Code in C in Linux Platform using fork.

Iterative TCP echo Server Code in C in Linux Platform

How data packets travel source to destination over the network

C Linux Code for multi threaded socket client/Server file sharing ftp

POSIX Semaphore Implementation Example code in C on Linux

POSIX Mutex Implementation C Program in Linux

No comments:

Post a Comment