在 C# 中使用一个套接字对象发送和接收多个套接字
在 C# 中,我有一个连接多个客户端的服务器应用程序。我只会在接受时实例化新套接字时跟踪 IP 地址和端口。我的问题是,仅使用一个套接字对象可以容纳发送和接收吗?同步和异步套接字都可以吗?例子会有所帮助。提前致谢。
In C#, I have a server application with multiple clients connecting. I will only keep track of the IP address and port when a new socket is instantiated upon accept. My question is that using only one socket object can I accommodate sending and receiving? Is it possible for synchronous and asynchronous sockets? Examples will be helpful. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 UDP 是可能的,使用 TCP 是不可能的,而且既然你提到了 Accept(),我假设你正在使用 TCP,因此这是不可能的......
It's possible with UDP, it's not possible with TCP and since you mention
Accept()
I assume you're using TCP and therefore it's not possible...您必须使用accept方法返回的套接字对象来向特定客户端发送和接收。您不能为所有客户端使用单个套接字。套接字是完成通信的端点
You have to use the socket object that is returned by accept method to send and receive to particular client. you can not use a single socket for all clients. socket is the end point through which communication is done