简体   繁体   中英

Sending messages from server to client c#

My client sends messages to the my server using tcp protocol (my server has a listener). 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. 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?

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/ .

If you want a WPF application example then see here http://www.networkcomms.net/creating-a-wpf-chat-client-server-application/

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