c# - unable to connect with a Server over the WAN using Client Server approach? -


i working on simple client server application, chat messenger. using client server approach. application works fine on lan local area network.but when try communicate sever out side lan. there no response client. while know server ip address (through external means ) uses broad band connection , resides on wan. think unable resolve ip address, or proxy problem occurs. can me out ? regards ! sm.abdullah

// /*   server program    */  using system; using system.text; using system.net; using system.net.sockets;  public class serv {     public static void main() {     try {         ipaddress ipad = ipaddress.parse("172.21.5.99");          // use local m/c ip address, ,           // use same in client  /* initializes listener */         tcplistener mylist=new tcplistener(ipad,8001);  /* start listeneting @ specified port */                 mylist.start();          console.writeline("the server running @ port 8001...");             console.writeline("the local end point  :" +                            mylist.localendpoint );         console.writeline("waiting connection.....");          socket s=mylist.acceptsocket();         console.writeline("connection accepted " + s.remoteendpoint);          byte[] b=new byte[100];         int k=s.receive(b);         console.writeline("recieved...");         (int i=0;i<k;i++)             console.write(convert.tochar(b[i]));          asciiencoding asen=new asciiencoding();         s.send(asen.getbytes("the string recieved server."));         console.writeline("\nsent acknowledgement"); /* clean */                     s.close();         mylist.stop();      }     catch (exception e) {         console.writeline("error..... " + e.stacktrace);     }         }  }  ---------------------------------------------------------------------------  /*       client program      */  using system; using system.io; using system.net; using system.text; using system.net.sockets;   public class clnt {      public static void main() {          try {             tcpclient tcpclnt = new tcpclient();             console.writeline("connecting.....");             // here local ip..              // if replace wan ip not communicate.             tcpclnt.connect("172.21.5.99",8001);             // use ipaddress in server program              console.writeline("connected");             console.write("enter string transmitted : ");              string str=console.readline();             stream stm = tcpclnt.getstream();              asciiencoding asen= new asciiencoding();             byte[] ba=asen.getbytes(str);             console.writeline("transmitting.....");              stm.write(ba,0,ba.length);              byte[] bb=new byte[100];             int k=stm.read(bb,0,100);              (int i=0;i<k;i++)                 console.write(convert.tochar(bb[i]));              tcpclnt.close();         }          catch (exception e) {             console.writeline("error..... " + e.stacktrace);         }     }  } 

have checked firewall / router?

most of time unsolicited incoming connections dismissed , fail because malicious in origin , nature.

you can around of these issues looking nat traversal

see: tcp client communicate server present in different network (nat issue)


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -