简体   繁体   English

从服务器发送消息到客户端c#

[英]Sending messages from server to client c#

My client sends messages to the my server using tcp protocol (my server has a listener). 我的客户端使用tcp协议将消息发送到我的服务器(我的服务器有一个监听器)。 I'm trying to send messages back from the server to the client, but I'm not sure what do I need to add to the client in order to get those messages. 我正在尝试将消息从服​​务器发送回客户端,但我不确定我需要添加到客户端以获取这些消息。 I tried looking it up, but I didn't understand how to implement it. 我试着查找它,但我不明白如何实现它。

Could you please assist? 你能帮忙吗?

这是完全相同的过程,但相反。

If you intend to receive messages independently (ie not in response to a request by the client), you need to make the client a TCP server, too. 如果您打算独立接收消息(即不响应客户端的请求),您还需要使客户端成为TCP服务器。 The client needs to implement exactly the same thing as the server you have now and the server needs to connect to the client. 客户端需要实现与您现在拥有的服务器完全相同的功能,并且服务器需要连接到客户端。

Can't you use WCF, which supports callback contracts? 你不能使用支持回调合约的WCF吗?

If you want a console example of a client server application using a network library see here http://www.networkcomms.net/how-to-create-a-client-server-application-in-minutes/ . 如果您想要使用网络库的客户端服务器应用程序的控制台示例,请参阅此处http://www.networkcomms.net/how-to-create-a-client-server-application-in-minutes/

If you want a WPF application example then see here http://www.networkcomms.net/creating-a-wpf-chat-client-server-application/ 如果你想要一个WPF应用程序示例,请访问http://www.networkcomms.net/creating-a-wpf-chat-c​​lient-server-application/

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

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