client server communication

client server communication
kick it on DotNetKicks.com

  I was wondering to know how two computers can communicate with each other then I came to know its a client and server who are responsible to setup that communication.
Well, client and server both are applications or you can say computer programs.

Server: Its an application which listens on port and serves the request.

Client:  It's also an application who sends a request to server on particular port.

  Lets take an example of web, where browser (IE, FF) are clients who sends the request to server on port 80.
On server, there are multiple applications who listens on particular port, like IIS service listens on port 80 where SQL server listens on port 1433. 
First browser should know the location of server. That's nothing but the IP address of SERVER.
Only one application can listens on port 80 it can be a IIS or Apache. Both applications can't listens on same port. That's why, if we tell the IIS to
listen on port 80 we need to tell Apache to listen on different port like 8080. So when request came to port 80, IIS will serve that request
and when request came to port 8080 Apache will serve that request.
If we are having two IP addresses assigned to the server then for IP address 192.168.1.1 we can tell the IIS to listen on port 80
and for IP address 192.168.1.2 we can tell Apache to listen on port 80. In this case requests coming to IP 192.168.1.1 port 80 will
get served by IIS and requests coming on 192.168.1.2  port 80 will get served by Apache. This is how we can resolve the conflicts.

   Lets talk about how Client communicates with server.
E.g. 
  Suppose, your IE requests a page http://www.google.com/. It will start establishing the communication with http://www.googe.com/.
During this time if you are trying to request another page of http://www.google.com/ it will establish another connection with server.
In first case, client needs to open a port with server lets say 1001 is opened to communicate with server and this port is engaged.
Means communication is not established yet. As 1001 is engaged second request opens next port 1002 with server and start communicating.
Server establishes the communication with port 1001 and responds to client on port 1001, for second request it responds to client
on port 1002.
You can use netstat command from command prompt to see foreign IP address , ports and local IP address, ports.
It also tell us the state of communication whether its established or waiting for server to respond.

TCP    smartmirror:1455       bom01s01-in-f86.1e100.net:http  CLOSE_WAIT
TCP    smartmirror:1495       digsby04.rit.edu:5222  ESTABLISHED
TCP    smartmirror:1497       69.46.36.6:http        ESTABLISHED
TCP    smartmirror:1501       bom01s01-in-f99.1e100.net:http  ESTABLISHE
TCP    smartmirror:1502       bom01s01-in-f147.1e100.net:http  ESTABLISH

Here smartmirror is my local IP and 1497 is my local port who established connection with foreign IP 69.46.36.6 on port http (80)

Conclusion:
When clients talks with server on port, it doesn't mean that clients needs to have port 80 open at his end.
Clients open the available port 1455 at his end and send requests to server on port 80. Server sends a response to client on
client side port 1455.
The detailed list of available port can be see here http://www.iana.org/assignments/port-numbers

There exists 0 to 65535 ports out of these ports, ports ranging from 49152 to 65535 are available for
dynamic or private ports.

I hope you got clear idea of how client communicates with server.

Satalaj
http://www.satalaj.com/

client server communicationASP.net monitor server MS SQL server shutdownC# send email using System.Net SMTP ClientAsp.net Create Folder On ServerServerTransfer vs ResponseRedirectAsp.net Interview Questions for 2 years or 3 years experianceAsp.net delete file file on Server C#.net and VB.net codesql server default portsUnable To Connect To The Remote ServerAsp.net Clientid

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.