tags:

views:

227

answers:

5

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?

A: 

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.

Eric J.
Could I also send large files this way?
Yes you can. You may want to consider embedding FTP in your application if that's your goal, though, since it's already well-designed to handle large file transfers. Here's an example of how to implement that: http://socketprogramming.blogspot.com/2007/11/file-transfer-using-c-socket.html
Eric J.
+1  A: 

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 (i.e. from the client to the server), depending on firewall configuration (such as NAT).

Kaleb Pederson
+2  A: 

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.

Alfred Myers
This is the only answer so far that makes any sense, considering that the OP does not appear to have much experience in network development.
John Saunders
A: 

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.

PlanBForOpenOffice