-1

I have started writing the server in Java, based on sockets and I have some questions. When I have the incoming request then ServerSocket returns Socket to me. Then I create the separate thread and use this new socket there. After some incoming requests, I have some separated threads and some sockets. All sockets use the same input address and port. Question -

How server understand to which thread he has to give input packet? Can you please give some advice about books or links that I can read to understand how the server works on low level?

How server (for example Apache tomcat) processing incoming sockets? As I understand, server has one input queue for input packet. Is this queue affects on the server's speed? Where can I read about such low level algorithm of server working?

user207421
  • 305,947
  • 44
  • 307
  • 483
Pavel
  • 11
  • 3

2 Answers2

0

The SocketServer listens on a specific host and port. So called a listening socket. As soon as the server receives a new connection request, the server creates a new socket and binds it to the new connection.

This link explains the process a little bit deeper.

I will take a look if I find any other good reading material.

Spitzbueb
  • 5,233
  • 1
  • 20
  • 38
0

Wernerson, thanks a lot! Good link! As I understand I was wrong because I think that socket is only combination destination ip + destination port. But socket is combination destination ip, destination port, source ip and source port. And, as I understand, when client application create some sockets (new Socket(destination ip, destination port)), then all these sockets will have the same destination ip + destination port, and, maybe, the same source ip, but they will have different source ports. Yes?

Pavel
  • 11
  • 3
  • 1
    A socket is a handle to a connection or an endpoint. That connection or endpoint has whatever properties it has. A listening socket is a handle for a different type of thing than a socket for a connection. TCP connections are identified by the source IP, source port, destination IP, and destination port. Your threads have handles that refer to TCP connections. – David Schwartz Jul 31 '17 at 10:33