简体   繁体   English

多个客户端-带有套接字tcp / ip c#.net的一个服务器连接

[英]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. 我想传达xml序列化对象,还需要发送和接收其他命令来调用方法。 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. 现在,我只是从C#和.Net套接字编程开始,发现异步I / O是必经之路,这样方法就不会阻止代码的执行。 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. 另一件事是,如果我需要开发自己的协议来区分我实际上是通过网络发送的内容-> xml序列化的对象还是一个可能只是用ascII编码的字符串之类的命令。 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... 我忘了提到我应该与服务器通信的某些客户端将是pda,因此我使用了紧凑的框架...因此这可能会带来一些限制...

您可能会发现我的一些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 . 我会放弃使用Sockets并切换到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. 它比.NET套接字要优雅得多,并且旨在以一种相当容易和简单的方式来完成您想要的所有事情。

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. 如果您想要使用它的指南,则有一组由Michele Leroux Bustamante撰写的令人惊叹的Microsoft网络广播 ,它们将使您立即启动并运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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