2

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?)

4
  • Can we have a code example please? Commented Sep 18, 2014 at 13:17
  • I dont really have code yet im still in the process of planning. Its a general question. Commented Sep 18, 2014 at 13:23
  • A feasibility study is an important part of technology selection. ie. Pick a technology and try it. If it fails and you don't know why, we would like to see that code. Commented Sep 18, 2014 at 14:04
  • 2
    No reason to change that opinion. The sockets will be asynchronous no matter what you do; if you use the asynchronous API you won't be over-taxing the system with threads sitting around waiting for communications and thus be more scalable. Commented Sep 18, 2014 at 15:03

2 Answers 2

3

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.

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

Comments

1

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

1 Comment

I have written modules that send data using TCP sockets across multiple threads. It is trivial with Socket.Send, and with SendAsync you just need to manage your buffers in a thread-safe manner.

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.