简体   繁体   中英

Asynchronous UDP Server for multiple clients in C#

I have a task to do and I am new to networking, so like to discuss before coding down. I have to write down server side UDP application. Server listens for connection request from many clients (could be 100 or more). When it receives it then it does some handshake, by sending acknowledge back and forth couple of times, with the client application to know its identity. When connection is established it receives different types of data from the clients which it does processing and put in the sql database and send acknowledge back to client. Periodically send command to clients for specific information it requires.

I am using C# with Visual Studio 2005. Should I use multi threading? threadpool? Asynchronous or sync UDP Server?

Thanks in advance.

Are you sure what you want is a UDP server? Terms such as "connections", "handshakes" are all TCP related.

I would use asynchronous methods in both the server and the client. It will complicate things, especially in the client.

The reason is that you write that the server will send stuff to the client sometimes. This makes a simple request/reply type of communication impossible (the client calls Send and then uses Receive until a proper answer have been received).

If you can scrap that requirement I would use synchronous clients (do some polling instead) which would make stuff a lot easier for you to understand.

If you have .Net 3.5, why don't you create a WCF service instead? It supports TCP and callbacks (server can call stuff in the client).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM