The document discusses socket programming for client-server communication between processes running on different machines. Sockets allow bidirectional communication and are identified by a combination of IP address and port number. The steps outlined include the server creating and binding a socket, listening for connections, and accepting clients. The client connects to the server and then bidirectional communication can occur, with the client typically sending the first message. Code examples of a basic socket server and client in C are provided to demonstrate the concepts.
1. Narayan Lal Menariya August 31,2018
Client – server communication using socket
When we use shared memory, messagequeueor pipes to achieveinter process
communication(IPC) than this can beachieved only and only if two process arerunning
on the samemachine. This kind of communication in which two processes arerunning
on samesystem and communicating with each other using IPC mechanismis termed
as Intra-Process Communication.
But assumethat if two process arerunning on two different machines than how they
will communicatewith each other. This problem can beresolved by Socket IPC.
Socket’s arenothing but kernel objects which act as an end point between two
machines. Do not assumethat socket will belikea wirewhich is used to achieveintra-
process or inter-process communication.
Sockets arespecial files which is thecombination of IP address plus Port number. for
exampleif your system’s IP address is : 10.0.5.15 and port number is 8000than socket
will be : 10.0.5.15:8000. By default sockets IPC is full duplex process and can beused to
achieve both intra-process and inter-processcommunication.
Socket Programming: In order to establish communication between two process using
socket they first need to follow somesteps as mention below.
pre-requirement:Pleasekindly go through theSocket system calls as i will not mention
return typeof system calls and data types. You can easily search them using command
“man socket”.
server steps:
1. A socket need to be creat using system call socket().
2. To achievecommunication between server and client , server need to be bind
with client using system call: bind().
3. Once binding is doneserver will listen client using listen() system call.
4. Now server needs to accept client request using accept() system call.
5. Now the connection is established so two way communicationca bestart. First
message will be send by client and server needsto send response.
client steps:
1. client will follow the same1,2 and 3rd steps.
2. now once binding is doneclient needs to connect with server using system call:
connect().
3. Now once theserver will accept it two way communicationcan beachieved.
Now here i am sharing my own written server-client codejust go through it and if find
any problem than feel free to ask.
Here note down that first message should be send by client.