Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-threaded network UDP server library for .net

Tags:

c#

.net

sockets

udp

Is there something like twisted (python) or eventmachine (ruby) in .net land?

Do I even need this abstraction? I am listening to a single IO device that will be sending me events for three or four analog sensors attached to it. What are the risks of simply using a looped UdpClient? I can't miss any events, but will the ip stack handle the queuing of messages for me? Does all of this depend on how much work the thread tries to do once I receive a message?

What I'm looking for in an abstraction is to remove the complication of threading and synchronization from the problem.

like image 441
Sam Coles Avatar asked Feb 11 '10 23:02

Sam Coles


1 Answers

I think you are making it too complicated. Just have 1 UDP socket open, and set an async callback on it. For every incoming packet put it in a queue, and set the callback again. Thats it.

make sure that when queuing and dequeueing you set a lock on the queue.

it's as simple as that and performance will be great.

R

like image 136
Toad Avatar answered Sep 17 '22 12:09

Toad