Sunday 15 March 2015

c# - Unable to connect from remote machine -


I have a problem and if I do it or not, then I can not see it at home. Here is the code

  using the system; Using System.Net; Using System.Net.Sockets; Using System.Threading; Using System.IO; Using System.Net.Security; Classroom Program {Private Static IPAddress ipAddress = IPAddress.Parse ("127.0.0.1"); Private static port = 6000; Private Static String Data = Faucet; Static zero main (string [] args) {thread thread = new thread (new threadstart (getredread)); Thread.Start (); Console.ReadKey (); } Get public static void () {while (true) {TcpListener tcpListener = new TcpListener (ipAddress, Port); TcpListener.Start (); Console.light line ("waiting for connection ..."); TcpClient tcpClient = tcpListener.AcceptTcpClient (); Console.light line ("Connected to {0}, tcpClient.Client.RemoteEndPoint); while (! (TcpClient.Client.Poll (20, SelectMode.SelectRead))) {Network Stream Network Stream = tcpClient.GetStream (); Stream Reader Stream Reader = New Streamminder (Network Stream); Data = Stream Reader. Readline (); if (Data! = Null) Console.light line ("Received Message: {0}", Data);} Console.lightline ( "Disconnected ... \ n"); tcpListener.Stop ();}}}  

I have a simple program to connect to this and Send a string with data and it works fine on the local host but there is a problem when I am trying to connect with each other.

I even locked the firewall on my PC and router Every time I tried to connect to my friend's laptop, then his computer refused. Maybe I am doing something wrong?

Of course, Code> ipAddress a local address , Because it is only working at this time. Any suggestions what to do?

It will have to be set to accept connections from any IP, where IPAddress overload function:

  System.Net.IPAddress.Any  

Use instead of 127.0.0.1 and it will fix your problem.


No comments:

Post a Comment