Click here to Skip to main content
15,307,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My question is: How to make socket or any other connection between two computers which are not on the same network. I tried to find out solution, but every thing i tried was working only on same computer (Server and client application running on same machine // localhost). I tried turning off firewalls but id did not helped.

Specifically what i want, is to be able to send string to remote computer, or any other object.


Any help would be appreciated :)
Posted
Comments
wizardzz 3-Feb-11 14:18pm
   
Um, as far as I can tell you do it the same way as the examples on local machines, except use the IP addresses of the boxes.

1 solution

You need to portforward the port chosen.
//client part
TcpClient client = new TcpClient();
client.Connect(new IPAdress(new Byte[] { 127, 0, 0, 1 }), 12345); //Replace 127,0,0,1 with your external ip and 12345 with the choosen port (and forwarderd on the server)
//Now its connected or it times out

//Server part
TcpListen server = new TcpListener(IPAdress.Any, 12345); //Replace 12345 with the forwarded port
server.Start(); //Start Server
server.AcceptTcpClient(); //Holds the thread till a client connects
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900