简体   繁体   中英

If my server knows a remote client's IP address, how do I send a message to the remote client?

The remote client is a desktop application running a windows.forms application. How do I have the server send the client a message, knowing the client's IP address?

Although sockets is an option, you may want to consider using a higher level abstraction such as the one provided by WCF.

WCF's Duplex Services allows you to implement communication going both ways (client -> server) and (server -> client) with some flexibility on choosing transport and protocol.

A common way to do this is using sockets .

Basically you open up a communication channel to the remote client using TCP/IP and can send messages back and forth. Both sides must know about the other and must agree on a message format.

When using sockets, you communicate on a port. Several ports are reserved for (or at least typically used by) certain protocols. For example, HTTP uses port 80 by default. You will want to select a port not already in common use. Also be sure that any firewalls between both ends allow communication on that port.

It could largely depend on the existing protocol that is being used between the client and the server. If the server is HTTP, then the client could poll to see if there are messages. If the client is already using TCP/IP, then ideally the server can send a message to the client any time it needs to.

Also, keep in mind that opening a communication channel may essentially be one way (ie from the client to the server), depending on firewall configuration (such as NAT ).

In general terms you do that by replying to a request of the client. If you don't have client requests, the distinction between servers and client becomes rather blurred.

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