TCP/IP POrt Connection establishment DOUBT

Status
Not open for further replies.

ashwinpr

Beginner
Hi,
I have a doubt with the TCP IP Port assignment & connection. ACtually,read abt it in coll....but then....now my brain doesnt remember much of the stuff.

ANyways..here is my doubt:
1. I have a Server which is hosting a streaming service on Port:80(just for an example).
Assume the URL to connect is :10.148.20.1:80

2. I have many clients arnd the world who would need to access this site and view the streaming video online.

3.I want to know if Port:80 would be used only for Connection establishment from the clients to the server or would data transfer also occur through port:80???

4.If POrt:80 is used only for connec establishment then is it that for each client there would be a separate port assigned on the SERVER for data transfer between the client & server.

5.If there are going to separate ports assigned for each client then would the server not be limited to serving just 65536 clients at a time??
Note:I believe 65536 is the max no.of ports in a comp.

Any help on this would be much appreciated.

Thanks
Ashwin.
 
The port would be used for connection and data transfer, Its upto the deamon process or the application listening at that port to provide multiple connection modules in it.

Earlier some servers used 2 ports. one to control and other for data transfer.

For Eg. In case of Apache server it spawns multiple child processes for each connection. These child processes then take care of the requests and stay resident for other requests. It can also launch a number of child processes if too many connections come, but if they are going above the limit set in config file then clients start getting error messages like too many connections etc.

Earlier apache used to span too many processes using unix fork command and then memory used to run out quick ( but these were OLD days. )

Once the process launches a child then it keeps a watch on the incoming IP address ( for eg ) and directs the packets form a particular IP to its handling process.

Wait for Kingkool and other to post and correct me also... :P
 
Hi ashwin,

The same port would be used. The daemon process running on the proxy would do the bid of having multiple connections.

:-)
 
Hi Guys,
Thanks for your reply.
Just waiting for King Kool to replies :)

There was a small discussion that we were having in office today abt this....
So thought ..best thing wud be to chk out with techenclave!

Waiting for more replies from other experts

BR\
Ashwin
 
Guys,

One more thing....where does the 'Socket' thingy come into picture here?

I am under the assumption that there would be sockets created at both the client & server ends which would bind to the server port.It is through these sockets that end-to-end communication take place.

I agree that all client sockets would first need to connect to a listening socket on the server side.( we usually say connect to a listeing port rather than socket)

After this,is it like...for every client connection there would be a corresponding server socket created on the server side. The comm then happens between the client socket & the server socket through Port:80.

Pls let me know if this assumption of mine is correct.

Thanks

Ashwin
 
Sorry ashwin,

i was wrong.

Server's port 80 is just used for conx establishment.

Once connected, a randomly available port on the server side would be used for data transfer and port 80 would be available for another conx.

I'll get back to you with more info on the same.

good day!
 
ashwin,

The client machine will connect to the server with a port of its choice and will try to connect to the server at port 80. Once it connects, a random port on the server will be assigned to the connection and port 80 is free to listen for more connections.

e.g.

client tries to connect from port 2345 -> server at 80(http)

Once conx is established. Server chooses a port and links it with client.

and 80 will be free again.

this happens until, all the ports are filled on the server.

Consider google for example, in india they have 3 servers performing the same operation done for load balancing. Hope u get it.
 
jayken said:
ashwin,

The client machine will connect to the server with a port of its choice and will try to connect to the server at port 80. Once it connects, a random port on the server will be assigned to the connection and port 80 is free to listen for more connections.

e.g.

client tries to connect from port 2345 -> server at 80(http)

Once conx is established. Server chooses a port and links it with client.

and 80 will be free again.

this happens until, all the ports are filled on the server.

Consider google for example, in india they have 3 servers performing the same operation done for load balancing. Hope u get it.

This is crap.

This would take out the whole concept of firewalls and stuff.

People block every other port and allow access only to port 80 of a webserver. Even if it assigns some other port after connection gets established then that port will need to be opened at the firewall so that client can contact. So does the administrator sit and keep opening ports till all ports are filled up ?

And about google and load balancing. The server load i.e. the system (CPU,HDD,Database) load needs to be balanced and not the ports. They use maybe DNS or some Hardware load balancers to balance out load between numerous web server ( am sure they are more than 3 ) so that each request is taken care of and no machine sits idle at peak time.

And port 80 i.e. http is a stateless protocol. i.e. there is no need of connection establishment, or in otherwords there is no connection made. The request comes and the server serves. Other than that there is no guarantee that the same server ( in case of load balancing ) or same child process will handle the request of the that client.

I think u are confusing between sockets and ports.
 
Josh said:
This is crap.
This would take out the whole concept of firewalls and stuff.
People block every other port and allow access only to port 80 of a webserver. Even if it assigns some other port after connection gets established then that port will need to be opened at the firewall so that client can contact. So does the administrator sit and keep opening ports till all ports are filled up ?

And about google and load balancing. The server load i.e. the system (CPU,HDD,Database) load needs to be balanced and not the ports. They use maybe DNS or some Hardware load balancers to balance out load between numerous web server ( am sure they are more than 3 ) so that each request is taken care of and no machine sits idle at peak time.

And port 80 i.e. http is a stateless protocol. i.e. there is no need of connection establishment, or in otherwords there is no connection made. The request comes and the server serves. Other than that there is no guarantee that the same server ( in case of load balancing ) or same child process will handle the request of the that client.

I think u are confusing between sockets and ports.

:) thanks for the reply man!
May be crap. But thats what I got from a pro.
I'll take your arguement to him.
good day!
 
OK, this is a fun discussion. The problem here is you guys don't seem to know the definition of a port, and definitely not that of a socket! A port is not a physical entity. It is just the multiplexing service that is the basis for a socket.
A socket is a connection identifier. It needs to be unique at the time it exists, that is, there cannot be two identical sockets in the system. Sure, you can reuse the socket (which will happen if the same client connects to your server again).
Now, a TCP connection is uniquely identified by its socket.
For now, consider the four fields of a BSD socket (some people say five, I never understood why).
1. Computer A IP
2. Computer A port number
3. Computer B IP
4. Computer B port number

Now do you understand why the port can be reused? Without any problems whatsoever? Even if items 1 and 2 are the same, it doesn't matter because items 3 and 4 will be different for each client!
Limitation: You cannot have more than 65536 concurrent connections with a single client. Which will never happen. Contention would not happen with HTTP, long lived connections like FTP might, but then you might think it good that a single client not be able to connect to you 65536 times.

In short, port 80 is used. For everything on the server side.

And port 80 i.e. http is a stateless protocol. i.e. there is no need of connection establishment, or in otherwords there is no connection made. The request comes and the server serves. Other than that there is no guarantee that the same server ( in case of load balancing ) or same child process will handle the request of the that client.
That isn't put very well Josh. You are right in that http is stateless, BUT http is an application layer protocol, so talk of connection establishment (or not, which is the domain of the transport layer) is misleading. You may be referring to a session (not the session defined in the session layer which does not exist for all practical purposes).

@Jayken, I think your pro might be referring to something called TCP handoff.
 
Wow wow,

Guys...thanks so much for ur time

I seemed to be convinced with Josh's n King Kool's comments.The firewall thingy of Josh was very logical.

So,can i safely conclude that only port:80 would be used on the server side for connec establishment,data transfer..no matter how many clients connect n transfer data from the server????

Thanks

Ashwin
 
As I said, TCP handoff might be happening there, and I don't know what exactly they do there. Why do you need to make these assumptions any way? Can you tell us what you are up to?
 
Hi King Krool,

Some of my friends & I were having this discussion about Ports & Sockets.

Two of them were insisting that each client would get separate ports on the server,once the connec was established through Port:80.

I was telling them that,that could not be the case.They were debating that 80 cannot be simultaneously used by so many clients at the same time.

I was explaining to them with the google.com example that up there in the prev post by jayken.

We even tried out with Ethereal port monitor software....we found that only port:80 was used on the server side,no matter how many clients conducted data transfers on the server side.

I thought I could chk it with Tech Enclave.This is my first thread here.

Anyways,to wind up:

Assuming there is no handoff n stuff happening here. Can we conclude that only Port:80 would be used on the server for data transfer no matter how many clients connect to it.

looking forward to your reply!

Thanks a ton guys for your time

Ashwin
 
Hmmm,

learning everyday thru tech enclave. :-)

Some effort from my side, used a tool to check out the ports used.

even used "netstat" in windows to check it out. port 80 and 443 is used for communication.

But I tried some googling to find how port 80 is used for multiple connections.

The request comes and the server serves.

I was wondering, how huge file downloads happens from such servers? Then the server has to tranfer data till its done. I am trying to find out how port 80 acts in such a scenario.

FIREWALL thingie was news to me :-D

Merci,

JayKen
 
My explanation is clear! Go through it. A socket is simply the identifier for a connection. And that identifier includes both sides (after the connection is established obviously). So there is no problem.
 
Wow.. See i told u wait for the kingkool to reply. He is one of the best at TE . ;)

Of course Port is not a physical entity.

See in case of port 80. U can program ur server to answer specific requests also. Create a socket and tie it up to a port to answer requests to say a particular IP ONLY. and another socket to answer requests from any other case. Then in that case u got 2 different sockets tied up to a single port ( 80 ). One handling a single IP and other handling all other IP's.

TWO SOCKETS CAN NEVER BE EXACTLY SAME. as king said.

See ur browser may contact from any vacant port but it has to contact port 80 only. And there will be the server who will handle ur request. And its not necessary that ur browser will send each request from the same port. It can send requests from different ports also but it will contact 80 only.

Its like an infinite loop. ( Dont go by the code its in Perl and most probably it wont work, just try to understand ). A small server code can be like this.

socket(SOCK,AF_INET,SOCK_STREAM,tcp); -> This will create a stream TCP Socket

$addr = sockaddr_in(80,INADDR_ANY);

INADDR_ANY = accept request from any IP. As i mentioned above. It will accept connections from even loopback.

bind(SOCK,$addr);

We now call bind() to assign a local address to a socket. We create a local address using sockaddr_in(), passing it our port 80 for the port, and INADDR_ANY as the IP address.

listen(SOCK,MAXCONN);

listen() is to make socket ready to accept incoming connections We call listen() to tell the OS that the socket will be used for incoming connections.

The listen() function takes two arguments. The first is the socket, and the second is an integer indicating the number of incoming connections that can be queued to wait for processing.

while(1) => This is the infinite loop, coz it a server which keeps listening.

{

$remoteadd = accept(SESSION,SOCK);
=> Create a handle to the socket.

while(<SESSION>) => While there is some data in the handle

{

$data=$_;

$reply=process_info($data);

print SESSION $reply;

}

}


This server can only process one client at a time. Because it has to reply to that connection and then go back to listen mode for the next connection. For handling multiple connection u need to use fork() Each time a new incoming connection is accepted, the server forks, creating an identical child process. The task of handling the child connection's I/O is handed off to the child, and the parent goes back to listening for new connections. When the child is finished handling the connection, it simply exits.

There are more like multiplexed server, multithreaded bla bla.

The point is....... ( hope u already got the point).

Oh and TCP Handoff ( the one king talked about ) is the one in which the client to told to contact the server at other port now coz they have dealt with the initial (whatever).

Is this correct king ? It is likely to happen in some authenticating servers. Radius maybe ?
 
Status
Not open for further replies.