Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous vs. Synchronous socket server for real-time application

I am currently developing a C# socket server that needs to send and receive commands to a real-time process. The client is an android device. Currently the real-time requirements are "soft", however in the future more strict timing requirements might arise. Lets say in the future it might be to send commands to a crane that could be potentially dangerous.

The server is working, and seemingly very well with my current synchronous socket server design. I have separate threads for receiving and sending data. I am wondering if there would be any reason to attempt an asynchronous server socket approach? Could it provide more stability and/or faster performance?

like image 514
Cartaya Avatar asked Aug 16 '11 14:08

Cartaya


People also ask

What is the difference between synchronous sockets and asynchronous sockets?

The send, receive, and reply operations may be synchronous or asynchronous. A synchronous operation blocks a process till the operation completes. An asynchronous operation is non-blocking and only initiates the operation.

Is TCP IP synchronous or asynchronous?

Use synchronous communication (TCP/IP) Synchronous communication provides a real-time response when sending data from a client to the Transfer CFT server.

Is socket programming asynchronous?

You can increase the performance and scalability of your client-server applications by using asynchronous sockets. Here's how. A socket is defined as the endpoint of a two-way communication between two processes running over a network. Inter-process communication can be achieved using sockets.

Is http synchronous or asynchronous?

HTTP is a synchronous protocol: the client issues a request and waits for a response. If you are using non-blocking (aka async) IO, the current thread of the client does not really have to wait, but can do other things (see above).


2 Answers

I'll gloss over the definition of real time and say that asynchronous sockets won't make the body of the request process any faster, but will increase concurrency (the number of requests you can take at any one time). If all processors are busy processing something, you won't get any gain. This only gives you gain in the situation where a processor would have sat waiting for a socket to receive something.

Just a note on real time, if your real time requirements are anything like the need to guarantee a response in x-time, then C# and .NET will not give you such guarantees. This, however, depends on your current and future definitions of "soft". It may be the case that you happen to be getting good response times, but don't confuse that with true real time systems.

like image 67
Adam Houldsworth Avatar answered Sep 28 '22 06:09

Adam Houldsworth


If you're doubting the usefullness of something asynchronous in your aplications then you should definitely read about this. It gives you a clear idea of what the asynchronous solutions could add to your applications

like image 38
Yurii Hohan Avatar answered Sep 28 '22 07:09

Yurii Hohan