Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronous and Asynchronous data transmission between client and server

I understand the concept of Synchronous and Asynchronous in the context of threading in a program, but I'm not sure what that means in communication.
More specifically, I'm confused about what it means to have an asynchronous communication between a server and a client...

In synchronous communication, and please correct me if I'm wrong, one side sends a message, then waits to receive a response, and when the response has arrived, it again sends a message and so on...
What happens in asynchronous mode?
I'm always imagining a two way pipe where there are no rules or protocols about whose turn is it to transmit information, and both sides just shoots bytes into the pipe whenever the feel like, and in both sides, the reading and writing to the pipe happens in two different threads. Is that the case?
That is, again, just a wild guess, if anyone have an explanation I'd love to read.

like image 691
so.very.tired Avatar asked Dec 08 '22 07:12

so.very.tired


1 Answers

You are right about the synchronous communication. For Asynchronous communication it works like this: The client sends a message to the server and optionally specifies what to do upon receiving a response from the server. In the mean time the client can go on doing other stuff, however when the server sends the response, the client knows what to do with that response and handles the response. This is typically done through a "callback" function.

Try to imagine this as sending and receiving email, you can send an email, but because you do not know how long it will take before the addressee sends you an email back you go on with your daily life. The addressee receives your email and sends you a response back. Upon receiving the email you decide the next step. I hope this explanation helps you conceptualize synchronous communication between client and server.

like image 105
NullPointer Avatar answered Dec 10 '22 21:12

NullPointer