In Socket programming, irrespective of whether you are writing code in C
or java
assume the following scenario.
Client has code similar to:
while(1) {
read(...);
/* process received msg */
process(received_msg)
}
Now, the client received msg1
and is busy processing it. This means the processor is now running some instruction inside process()
. At this point, msg2
arrives. But, there is no read()
blocking now to receive it. What happens to the incoming message msg2
now?
Does it depend on the protocol? Does it depend on the language api?
I think if I make a new thread every time I receive a message I can overcome this issue. My question is aimed at understanding what happens in a single threaded context, and if there's any way to make this work without using multiple threads.