File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes How webserver knows which client to reply Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How webserver knows which client to reply" Watch "How webserver knows which client to reply" New topic
Author

How webserver knows which client to reply

Micheal John John
Greenhorn

Joined: Mar 02, 2014
Posts: 3
Hi all,

I am newbie and started to learn java and servlets.
I have below query, I am running webserver in port 80.
Client A connects to the webserver and requesting some file.
Client B connects to the webserver at the same time and requesting for some other / same file.

How the webserver exactly knows how to serve the intended client? Meaning not resulted in serving wrong files to wrong client. This is for HTTP case.

How about normal TCP..instead of running webserver...writing socket pgm...like I am running some standalone java pgm in special port say 905.
Client A directly connects to this port thru TCP and send some raw string for processing.
Client B also connects to this port. How will work in this case?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3605
    
  14

Hello Micheal, welcome to CodeRanch!

In both cases it works the same, because HTTP is implemented on top of TCP/IP. The client sends a request, in the form of TCP packets. These packets contain the ip-address of the client, plus the port number. Together they form a socket. When two requests come in from different hosts, the server will simply return data to the same socket the request came from.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2280
    
  28

Yeah, it's kind of a wonderful thing how this whole internet works . Ultimately, at the physical level, a given computer can only talk to the network it's physically connected to. How does it manage to communicate to a server located across the world? To understand this well, you need to understand the OSI model of networkng. I can't even begin to do justice on the subject in a post. I spent 1 semester taking an intro course on networkng in my bachelor's course, an 3 years forgetting it

If you really want to understand how networkng works, I'm afraid you will either have to go to school, or pick a textbook
Micheal John John
Greenhorn

Joined: Mar 02, 2014
Posts: 3
Thanks a lot Stephen and Jayesh. I started to explore more on this...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How webserver knows which client to reply
 
Similar Threads
How many requests can handle a port at 'a' time
getLocalPort()
SocketPermission, Remote Port?
A question on multiple tcp listeners for the same port?
http - https - load balancer - web Server - app Server