0

Speaking in high-level terms, suppose I have a server that capitalizes whatever strings it receives on the port it is listening to, and then returns them. It is on the same physical machine as the applications sending/reading the strings. For definiteness, we're on Linux or Windows. Would the following correctly describe the situation?

Our server interacts with two connections. The first is a connection from the application sending the string from localhost:port1, and the server is listening on localhost:port2. Then, after processing, it sends the capitalized string from localhost:port3 to an application listening on localhost:port4 that can read the packet.

So we have: localhost:port1 -(lowercase string)-> localhost:port2; then localhost:port3 -(uppercase string)-> localhost:port4.

Would this be an accurate portrait of how our server would interact with the machine's ports? In particular, must port1 through port4 be actually distinct ports?

user207421
  • 305,947
  • 44
  • 307
  • 483
shintuku
  • 223
  • 1
  • 6
  • It depends how they are connected. If both applications are clients, the server only uses one port. If the server is a client of the second application, there are four ports. – user207421 Aug 11 '23 at 01:32
  • @user207421 I see! But in what sense would the server use only one port? Suppose both applications are clients of our server. Then, does the server interact with one port for listening and one port for returning the capitalized string? – shintuku Aug 11 '23 at 01:36
  • No. The server listens on a local port and accepts connections. The accepted connections use the same local port. – user207421 Aug 11 '23 at 01:39
  • Duplicate of [How does the socket API accept() function work?](https://stackoverflow.com/questions/489036/how-does-the-socket-api-accept-function-work) and many others. – user207421 Aug 11 '23 at 01:44
  • @user207421 For the moment that link clarifies it, thank you very much for your help and time! – shintuku Aug 11 '23 at 01:49

0 Answers0