Socket: A Socket is one endpoint of a two way communication link between two programs ,running on the networks. The two programs can be same or different machines. A socket is bound to an IP address and port number .Normally a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request.


On the other hand , the client knows the hostname of the machine  on which server is running  and the port number  port number on which server is listening . To make a connection request the client tries to rendezvous with the server on servers machine and port. The client also need to identify itself to the server , so it binds to a local port number that it will use during the connection

If every thing goes well ,the server accepts the connection upon acceptance the server goes to a new socket bound to a local port number and also has a remote port endpoint set to the address and port of the client .It needs a new socket so that it can continue to listen to the original socket for connection requests which tending to the needs of the connection client.


On the client side ,it the connection is accepted ,a socket is successfully created and the client can use the socket to communicate with the server .


Types of Socket:

There are four types of Sockets available for the users .The first two are commonly used and the last two are rarely used .

They are-

1)Stream Socket

2)Datagram Socket

3)Raw Socket

4)Sequenced packet Socket


1:Stream Socket:-


Delivering in a networked environment is guranted .If you send through the stream socket three items “A”,”b”,”C”,the will arises the same order –“A”,”b”,”c”.This socket use TCP(Transmission control protocol )for the data transmission .


2: Datagram Socket:

Delivering in a network environment is not guaranted .The are connection less because communication process need not set up a connection before the exchange messages.Instead ,Sender specifies a destination address on cach message.There is no guarantee that recipient will be ready to receive the message and there is no error returns if the message can not  be delivered .This socket we use UDP(user data protocol) for data communication .