D4rth B4n3
D4rth B4n3

Reputation: 1278

C# async socket reading and writing at the same time?

I am writing a tcp chat server at the moment and i read a lot of articles about synchronous and asynchronous sockets.

I decided to use the async sockets because this way i don't have to manage the threads myself.(Anything reason i should to change my opinion ?)

In all the articles, it was nicely explained how to establish a connection and how to send and receive data BUT never what happens if there might be more than one message to send without a reply.

My Question is do i have to call socket.endreceiving() before i want to send something ??? If i don't what would happen if i receive a message at the same time i want to send one ??? (there are multiple threads but its still one underlying socket right?)

Upvotes: 2

Views: 3318

Answers (2)

vtortola
vtortola

Reputation: 35965

Find there an example of asynchronous TCP listener and client https://github.com/vtortola/AynchronousTCPListener

You can send and write and the same time, you cannot send from two threads at the same time through the same socket.

Upvotes: 3

jeoffman
jeoffman

Reputation: 1487

In my experience this is not a problem for Socket.Send or Socket.SendAsync

Upvotes: 1

Related Questions