Question:
Socket ==> Synchronous vs Asynchronous ?!?!?!?
aryaxt
2009-01-19 18:23:35 UTC
Whats the difference between asynchronous socket and synchronous socket? I thought the difference was just that in asynchronous the socket sends and receives data on a separate thread.

My client connects to an echo server, but we have a server and I could not connect to it. It would keep disconnecting me. So I talked to the developer of the server , and he said the reason i get disconnected is that I am not using an asynchronous socket.
What the heck does that mean? what difference would that make, I still should be able to send and receive messages huh?
Three answers:
Icarus Rising
2009-01-19 23:55:35 UTC
All sockets are asynchronous and use a seperate thread because of the basic nature of the I/O. However:



When you want to receive data from a socket, you can simply call a receive data method. However, if the data is not immediately available, then your thread will block. Most socket API's have a timeout exception that will be thrown if you don't receive data within some set time period. At this point, your program can give up or try again, but either way, all this blocking blows. This technique is using sockets synchronously.



Alternatively, you can poll your sockets for data. Actually, a lot of socket libraries will simply call you back when data is available (real async). If there is no data, you just go on with your life. In this case, there is no timeout, because you won't call read unless there is actually data waiting for you. This technique is asynchronous.



By the way, though C and the like had asynchronous socket, if you were programming in Java before 1.3 or something, you ONLY had blocking I/O. I was doing network programming in C++ at the time, so I got to skip out on that whole headache.
2016-12-09 00:27:50 UTC
Asynchronous Socket
Rick B
2009-01-19 19:35:53 UTC
Asynchronous sockets are usually defined by the server side application and not by what the client's doing. I'm apparently wrong per your developer, but I thought an asynchronous socket allows multiple connections by forking or threading. A synchronous socket processes one request at a time.



Perhaps he means the clients should not expect a fixed send,rx,send sequence but rather needs to send EOT codes...grasping at straws now.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...