Tuesday, November 11, 2008

Client Server Communication with the help of Sockets

A socket is defined as an end point for communication between client and server.A socket is identified by a IP address concatenated with the port number.In general all sockets work on the client server architecture.In server client system, server waits for the incoming client request by listening to a specified port.Once the server received the request from the client it accepts the connection from the client socket to complete the connection.As there are some standards ports already defined for some specific services like a telnet server listens to port 23,a ftp server listen to port,a http server listens to port 80.All ports below 1024 are considered well known and we can use them to implement standard devices.Now when a client process requests to initiates a connection with the server,it is assigned a port by the host computer.This port is some arbitrary number greater that 1024.

Let us consider a example,there exists a client on host with IP address 185.145.23.87 wishes to establish a connection with the web server which is listening on the port 80 and having IP address 164.25.17.5,now let host X is assigned a port number 1547.Now this connection will contain a pair of sockets (185.145.23.87:1547) on host X and (164.25.17.5:80) on the web server.Now the packets traveled between the hosts are delivered to the appropriate process based on the destination port number.The main thing that kept in mind during connection that all connections must be unique,that means if another process on host X wants to establish a connection with web server then the port number that is assigned to this process must be greater that 1024 and different from 1547.

Hope you found this post useful.Waiting for your responses for further improvement.
Thanks for visiting.