I am trying to write a multi-client socket system which communicates via strings sent by the client, which will trigger an event according to its content.
There is a lot of materialon how to do it, but I cannot grasp the logic behind it.
In this example and enter link description here in this one, there is a while true piece of code which has two main instructions:
socket.accept();
Thread t = new Thread(runnable);
I cannot understand how this works:
- the while(true) continuously passed over those instructions, but creates a Thread only when the accept() method clicks?
- Does the new thread have a dedicated port? Isn't the socket communication one on one?
- How does the software keep track of the spawned socket threads, and does it actually matter?
- How do I send a reply to the thread that just wrote me?
Maybe it's my lack of google skills, but I cannot find a good tutorial to do this stuff: help?