0

I need to implement a TCP client that will send data to the server and also receive messages. The communication model should be asynchronously. Do you have a good example of doing this? Do i need to implement that on another thread ... that keeps constantly reading from the socket? ... or I can use the BeginReceive pattern of the socket?

Thanks, Radu

1 Answer 1

1

When you connect over TCP to the server you get a duplex channel so the server can talk back to the client in the same socket.

About using the begin receive you can use it to avoid creating worker threads and constantly reading the socket (the same way you can use BeginSend). Without anymore information about what you're trying to do, that's the best I can give you... yes you can. :)

Sign up to request clarification or add additional context in comments.

3 Comments

do you know an article that shows me how to set a class (session in my case) that has a method to send messages and constantly receives all messages from the server. The problem is that I send a message and I expect an answer after a while ... but in that time the server may send me a lot of messages.
Not really, but what you want is to do a BeginReceive and in the AsyncCallback do another BeginReceive (so that you loop on receiving asynchronously). Of course managing the application protocol when you're talking about non sequential sends and receives is another story.
I think that I missed that part with another BeginReceive

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.