I got a trainee in the company I work for. We are currently working on a JS interface that communicates through websocket with a C/Lang server. My trainee asked me a very good question this morning.

I quote :

"I understand the system of sending and receiving messages, but how the computer actually receives and forwards the message to the running code".

I tried to explain how, but I failed as I don't know how to softly introduce port interactions.

The problem is that I feel that the trainee doesn't understand. I know that these kind of questions can get stuck into the head of a programmer and make him/her more hesitant in front of code and I don't want that for my trainee.

Can someone with good explanation skills help me make a simple, yet complete, answer to this question?

Any help would be much appreciated.

closed as too broad by gnat, Andres F., Jörg W Mittag, Robert Harvey, 17 of 26 Nov 2 '16 at 18:34

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
  • Analogy always works well. Think of a pigeon box in a hotel receiption. – tofro Nov 2 '16 at 15:43
  • Okay so i may take a everyday situation and fit it to how computer run. I ll try to write something with this idea in mind and try it. – Hakeem El Bakka-lee Nov 2 '16 at 15:47
  • I'd start with "All internet connections go through the Internet Protocol" (en.wikipedia.org/wiki/Internet_Protocol), which is implemented in almost every computer and every software (either directly, by using libraries or the OS-supplied functions). If you start with that, you can go up the stack in any direction: TCP/UDP, HTTP etc. – Hubert Grzeskowiak Nov 2 '16 at 16:02
  • 2
    a system of tubes – Ewan Nov 2 '16 at 16:37

I always think of it as:

  • The port is an address on the incoming packet
  • The operating system has been told to put any messages coming into the computer with that port address to a particular place in memory
  • The program knows to look at that memory address to find its messages
  • The bindings are a series of processes in your program telling the operating system, the program etc where and what to look out for, which is why you need more than 1 to get everything working. Outgoing is pretty much the same but in reverse

Not the answer you're looking for? Browse other questions tagged or ask your own question.