简体   繁体   中英

multiple clients - one server connection with sockets tcp/ip c# .net

I need to develop a client server system where I can have multiple clients communicating with one server at the same time. I want to communicate xml serialized objects and also need to send and receive other commands to invoke methods. Now, I am just starting with socket programming in C# and .Net and found that the asynchronous I/O is the way to go so that the methods dont block the execution of code. Also there are many examples of how to

make a simple client server system. So I have a basic understanding of how that works.

Anyway, what still is not clear to me is how I can set up a server which can manage connections to multiple clients? Can I just create a new socket per connection and then store those in some kind of list? Do I need some kind of multiplexing to achieve this? Do I have to listen at multiple ports? What`s the best way here?

And the other thing is if I need to develop my own protocol to differentiate between what I am actually sending over the network --> xml serialized object or a command which might be just a string encoded in ascII or something. Or would I develop my own protocol just to send these commands?

Any kind of help is apreciated! If someone knows a good book which covers this sort of stuff, let me know. Cheers

I forgot to mention that some of my clients which are supposed to communicate with my server will be pda and I therefore use the compact framework... So this might bring in some restrictions...

您可能会发现我的一些TCP / IP .NET FAQ条目很有用,特别是使用套接字作为服务器套接字 ,该套接字解释了侦听服务器如何创建新的客户端连接,而XML over TCP / IP则讨论了您必须为此做出的决定。 TCP / IP上的XML协议。

I would abandon your plan to use Sockets and switch to WCF Windows Communication Foundation . It's far more elegant and is designed to do all the things you wanted, in a considerably easier and simpler way than .NET sockets.

If you want a guide of how to use it, there are a set of amazing Microsoft webcasts by Michele Leroux Bustamante that will have you up and running in no time.

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