c# - No connection could be made because the target machine actively refused it - Socket Program -


the problem im facing given in headline. :

  • got socket server , running on port 61911 :

    _server.bind(new ipendpoint(ipaddress.any, 61911));

  • and port (61911) opened globally , set server ip address 192.168.1.2 (my pc)

  • firewall , antivirus programs dealed well.

  • ran socket server , got port open status yougetsignal.com

pic :

http://img189.imageshack.us/img189/1777/x07w.png

  • and while ^checking, socket server responded well, think means established connection server im hosting.

  • but when accessed through client, error specified 'no connection made...'

here code use connection in client :

private static void loopconnect()     {         while (!_client.connected)         {             try             {                  ipaddress ip = ipaddress.parse("**public ip**");                 ipendpoint remoteep = new ipendpoint(ip,61911);                 _client.connect(remoteep);             }             catch (socketexception e) { console.writeline(e.message); }         }          console.writeline("connected!");     } 

and code handles accepting in server :

private static void setupserver()     {         console.writeline("setting server.. ");         _server.bind(new ipendpoint(ipaddress.any, 61911));         _server.listen(4);         console.writeline("server up!");         _server.beginaccept(new asynccallback(acceptcallback), null);     }      private static void acceptcallback(iasyncresult ar)     {         socket socket = _server.endaccept(ar);         _clients.add(socket);         socket.beginreceive(_buffer, 0, _buffer.length, socketflags.none, new asynccallback(receivecallback), socket);         _server.beginaccept(new asynccallback(acceptcallback), null);     } 

so think thats information regarding problem can give ..

*evrything regarding malware protection, firewalls, port forwarding.. done. *and port open in netstat -anb

solutions appreciated :)

edit : client sends request , server acknowledges. think doesnt reach client. should else in router porting 'inside'. how possible ???

what happens this:

  1. client tries connect public ip.
  2. in doing so, connect gateway (which router)
  3. your router denies access on port, because opened outside, not inside.

to test application, use local ip (192.168.1.2). when deployed, can use outside address. open port forwarding inside in router, outside scope of answer.


Comments