views:

697

answers:

2

Hello everyone,

I want to use WCF to enable two way communication without opening a port on the client.

I'm developing something like a P2P application (similar to teamviewer/logmein) where you don't need to open ports to communicate.

How do I accomplish two way communication through HTTP/HTTPS without the need to open a port in the client?

Note : Port 80 can be opened in the server...no issues on that.

Thanks

+1  A: 

I'm not sure I understand. The purpose of digital firewalls is (generally) control communication channels. If you want to communicate bypassing firewalls you have two choices.

  1. Hide the message in something the firewall lets through
  2. Use a communications channel the firewall doesn't control

In the case of the earlier:

You could pass messages to proxy that passed them on (email is a good but not exactly responsive example).

In the case of the latter:

You could put the messages on say file where some other transport layer carries them

Preet Sangha
In other words,I'm trying to tunnel things through ANY one port.I cannot make users do portforwarding and open ports on the client side to receive incoming connections.
Josh
+2  A: 

Well those systems you mention work as follows. They first try to make client A and client B communicate directly via a range of different topologies which basically require one of them to allow incoming connections if that fails they fall back on a third party which acts as a man in the middle. So client A talks to the server and sends it messages for client B. Then Client A gets the messages addressed to it back in response. Client B sends it messages to the server and it's gets the message from client A back from the server. This way both client A and B always initiate the connection and don't need to have a port open for incoming traffic.

If I understand correctly in your case you would always want the man in the middle. In order to do this you would have to write a WCF service that provides all relevant methods. For instance things like

  • void SendMessageToClient(Guid senderId, Guid recipientId, Message msg)
  • Message[] GetMessages(Guid recipientId)

then have those methods respectively store and retrieve those Message objects from somewhere (like a database or a queue or something).

Then write a client that connects to the WCF service using the HTTP binding and call the methods on the server and process the results.

I hope you understand that

  • a) this isn't a very efficient way to communicate.
  • b) that it's difficult to test and debug and understand whats going on since there are so many parties involved and communication is asynchronous living in 3 different processes.
  • c) it adds an extra layer ontop of the communication so you need to keep it clear for yourself in your head (and prefereably in code) when you are dealing with the infrastructure bits and when you are dealing with the actual protocol clientA and clientB speak to each other in the Message objects.

Pseudo (code) Example

in this example I assume the message object is nothing more then a string and the only command is "whattimeisit" to which the response is the local time in string form

  • ClientA makes call to server.SendMessageToClient("clientA", "clientB", "whattimeisit");
  • Server stores this message in the database with ID 1
  • ClientB makes call to server GetMessages("clientB");
  • Server retrieves message with ID 1
  • ClientB recieves back "whattimeisit" as a response
  • ClientB makes call to server.SendMessageToClient("clientB", "clientA", "19:50:12");
  • Server stores this message in the database with ID 2
  • ClientA makes call to server GetMessages("clientA");
  • Server retrieves message with ID 2
  • ClientA recieves back "19:50:12" as a response
olle
Hi,in your pseudo code...see this part "ClientB makes call to server GetMessages("clientB");"....If I use a timer for this,it'll consume a lot of bandwidth on my server right? The topology and everything is absolutely right. This is what I need. But,I need to accomplish this in a real world scenario
Josh
So,i thought that the way to do it was to let the clients connect to the server and keep their session open. and let the server call the method on the client through the same session...Is there any other way? (I can't use a timer since multiple clients doing that would consume all my server's internet bandwidth)
Josh
As far as the bandwidth goes. The bandwidth used will be dependend on the size of the message object primarily. The bigger strain will be the number of concurrent connections this depends ont he number of similtanous clients. WCF scales very well you should be able to process allot of request/sec and if need be you can add extra servers they arn't that expensive anymore. I don't know what type of communication you want to do and how high/low the number of reqs/per client/per timeframe will be.
olle
Yes you can also use a DuplexBinding which is what you describe.
olle