In this chapter we shall learn about Linux Sockets.
Linux sockets is one of the IPC (Inter Process Communication) mechanism.
It will give 2 way communication between 2 processes, they can be one system or in different system.
Once the socket is established, data can be transfered in both the direction, till any one closes the connection.
Different types of Sockets:
There are 3 types of sockets:
1. Stream socket:
1. Also called as TCP, Transmission Control Protocol
2. They are reliable, sequenced.
3. Socket type is SOCK_STREAM
4. Connection oriented.
5. They are used in persistent connection and with large data capacity.
2. Datagarm Socket:
1. Also called as UDP, User Datagram Protocol
2. out of order, duplicates possible
3. No acknowledgements
4. No retransmissions
5. connectionless
6. Socket type is SOCK_DGRAM
3. Raw Socket:
provides access to the underlying communication protocols.
For every socket programming, there will be 2 entities.
1. Server: It will wait for client to send a message.
2. Client: It will initiate communication. It must know the address and port of the server.
Terms used in socket programming:
Socket: Create a new communication entity
Bind: Attach a local address to a socket
Listen: Socket is open and ready to accept connections.
Accept: It will block the caller, until connection request arrives.
Connect: First step in establishing a connection
Send: Send data over a connection
Receive: Receive data over a connection
Close: Close the connection.