Asynchronous TcpListener and TcpClient design patterns
-
Are there asynchronous code designs for a server and a client using TcpListener and TcpClient including asynchronous data read/write?
Чесноков
-
Are there asynchronous code designs for a server and a client using TcpListener and TcpClient including asynchronous data read/write?
Чесноков
If you don't mind using WCF, you can get the async for free (along with several other benefits). /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
If you don't mind using WCF, you can get the async for free (along with several other benefits). /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
No, I need to use TcpListener and TcpClient in .NET assembly for windows forms. I'm intrested in correct usage of begin accept, read, write for server and begin read, write for client. Also correct server shutdown, socket exception handling etc...
Чесноков
-
Are there asynchronous code designs for a server and a client using TcpListener and TcpClient including asynchronous data read/write?
Чесноков
-
Documentation encourages to use TcpListener and TcpCllient classes. I've seen those samples with a server getting back data from a client, sending back response and closing it. I'm intrested in a server handing many clients connected and client connected to many servers architecture. There should be some ready described solutions to avoid common mistakes. e.g. in BeginRead callback there is a missing zero byte call back which occurs if client connection is lost
Чесноков
-
Documentation encourages to use TcpListener and TcpCllient classes. I've seen those samples with a server getting back data from a client, sending back response and closing it. I'm intrested in a server handing many clients connected and client connected to many servers architecture. There should be some ready described solutions to avoid common mistakes. e.g. in BeginRead callback there is a missing zero byte call back which occurs if client connection is lost
Чесноков
Wow, this seems to be a good candidate for WCF! The WCF service doesn't need to be hosted in a server app - you can use it much like you'd use
TcpListener
andTcpClient
. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Documentation encourages to use TcpListener and TcpCllient classes. I've seen those samples with a server getting back data from a client, sending back response and closing it. I'm intrested in a server handing many clients connected and client connected to many servers architecture. There should be some ready described solutions to avoid common mistakes. e.g. in BeginRead callback there is a missing zero byte call back which occurs if client connection is lost
Чесноков
Chesnokov Yuriy wrote:
I've seen those samples with a server getting back data from a client, sending back response and closing it.
I'm intrested in a server handing many clients connected and client connected to many servers architecture.There is no multiple/multiple architecture, it's always one server/many clients. The fact that your browser can open multiple pages is due to having multiple clients, that each request data from a different server.
Chesnokov Yuriy wrote:
There should be some ready described solutions to avoid common mistakes.
The All-in-one samples refer to the same page[^].
Bastard Programmer from Hell :suss:
-
Wow, this seems to be a good candidate for WCF! The WCF service doesn't need to be hosted in a server app - you can use it much like you'd use
TcpListener
andTcpClient
. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
Well I'm developing according to domain-driven design DDD and was going to write a service for server and client. What is the advanatage of WCF over ordinary .NET sockets apprach? I need several services running on the same machine each with a different port.
Чесноков
-
Well I'm developing according to domain-driven design DDD and was going to write a service for server and client. What is the advanatage of WCF over ordinary .NET sockets apprach? I need several services running on the same machine each with a different port.
Чесноков
WCF provides the plumbing for easily:
- building a configuration (port, transport, security) driven client/server system
- implementing both sync and async client APIs
- adding hooks (e.g. custom compression) before data is sent/received
- implementing logging and instrumenting traffic
- implementing handshaking (full-duplex) communication and transacted communication
- embedding the server in any type of host host (GUI app, console app, web app, Windows service)
If you haven't had the opportunity to use it, I recommend giving it a try. I think you'll be pleasantly surprised by its power and ease of use! Here are a couple of links that should get you up and running quickly:
- WCF Introduction - Part1[^] (CP) <-- recommended
- WCF Getting Started[^] (MSDN)
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
WCF provides the plumbing for easily:
- building a configuration (port, transport, security) driven client/server system
- implementing both sync and async client APIs
- adding hooks (e.g. custom compression) before data is sent/received
- implementing logging and instrumenting traffic
- implementing handshaking (full-duplex) communication and transacted communication
- embedding the server in any type of host host (GUI app, console app, web app, Windows service)
If you haven't had the opportunity to use it, I recommend giving it a try. I think you'll be pleasantly surprised by its power and ease of use! Here are a couple of links that should get you up and running quickly:
- WCF Introduction - Part1[^] (CP) <-- recommended
- WCF Getting Started[^] (MSDN)
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
Thanks, but I'm not sure that is suitable for my design. I'm coding video surveillance application, server runs video capture and sends captured frames to connected clients. There can be any number of clients connected to a server and a client can be connected to any number of servers. There are video capture service and video data transfer service (the server). As the frame is captured video capture service invokes send method from the video data transfer service which sends the frame to all clients connected. WCF as I understood provides service contract and public methods to call. In that case I need to add WCF logic to video capture service and declare public method as e.g. GetRecentFrame(). And a client needs to call that method. I do not want to combine video capture and video data transfer services. As video capture service is running on despite the fact if someone is connected to transfer it a frame. And network connection may be slow, video capture service may get 10 frames in a time 1 frame is finished with the transfer to the client.
Чесноков
-
Thanks, but I'm not sure that is suitable for my design. I'm coding video surveillance application, server runs video capture and sends captured frames to connected clients. There can be any number of clients connected to a server and a client can be connected to any number of servers. There are video capture service and video data transfer service (the server). As the frame is captured video capture service invokes send method from the video data transfer service which sends the frame to all clients connected. WCF as I understood provides service contract and public methods to call. In that case I need to add WCF logic to video capture service and declare public method as e.g. GetRecentFrame(). And a client needs to call that method. I do not want to combine video capture and video data transfer services. As video capture service is running on despite the fact if someone is connected to transfer it a frame. And network connection may be slow, video capture service may get 10 frames in a time 1 frame is finished with the transfer to the client.
Чесноков
Ah. I now understand why you prefer to be lower in the network stack. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Are there asynchronous code designs for a server and a client using TcpListener and TcpClient including asynchronous data read/write?
Чесноков
I don't know if it counts as a design pattern but my sockets library[^] may be of some use to you (either to use it or to look at the code to adapt for your own solution). I don't use asynchronous writing (writing is de facto asynchronous, as it writes to the local buffer immediately, so you only need to use the methods if you want feedback), but I do use asynchronous accept and read and handle the various ways in which it can go wrong unexpectedly.