Sunday, 26 January 2014

Basics of socket programming

 




Socket is basically an end point of an Inter process communication.

Wonder what is Interprocess communication?

It is the process of communicating between the two threads(process), that run on the system concurrently.
Sockets are bidirectional. That is we can send and receive data at both of the ends. This is point to point communication and communication in socket will happen as connection oriented(stream) or connection less(datagrams).
Socket address:

Socket address is the combination of IP address and port numbers.

IP address is address that uniquely identifies your computer. when you are transferring the packet from one computer to other computer. you need a IP address to transfer it. It like a address which we give to courier man. Upon reaching the destination, you need to find for which member of the family the courier has been arrived. It may be for you, or for your brother, mother. How to find that? For that purpose the port number is used. As such there are different members in the family there will be several process running on the system. Here the port number decides for which process the packet has to be delivered. Here the family members can be http, SSH, HTTP secure, web browser. For this some port number will be user defined and predefined also. Predefined are take cared by IANA(internet assigned numbers authority)

API:

There is no built in programs in c for sockets. Widely there is two API available..
1.      BSD sockets (Berkeley socket distribution)
2.      winsock (Windows sockets)


Socket programming you have written is an part of application layer. All the low level code are covered by Berkeley in BSD socket programming. we use the application programming interface in the application layer.