I am writing socket client for IO device, which is the tcp server. I am able co connect and listen for data which the server periodically sends. But from time to time, I need to send some instruction to the server and read its response.
What is the proper way to handle this task, to be able listening for incoming data and after instruction is sent, receive response and to know, witch part of received data the response is?
What if device is sending data, while I need to send data to device? how can I dispatch such traffic? Do I need one thread to read and one for writing? Is it possible to handle this using single thread per device (there will be up to hundreds of devices connected)?
I am using Socket.Receive and Socket.Send methods.