c# - WebSocket serverSocket.Accept() doesn't trigger -


i trying send strings server using synchronous websockets in c# console application. following code works flawlessly on 127.0.0.1 doesn't work on real server tried. result client connects ip/port , sends strings no errors, _serversocket.accept(); never triggers when _clientsocket.connect(_ip, _port); called.

also, if serversocket.bind(new ipendpoint(ipaddress.any, _port)); not called, sender gets error (as expected) when trying connect. seems should work , port working.

i tried using variety of servers. 1 in sample code below taken https://server.pro/

so, question is, why doesn't _serversocket.accept(); trigger, since sender can connect , send strings no errors ?

private static socket _serversocket, _clientsocket; private const int _port = 40288; //this ip doesn't work, 127.0.0.1 works flawlessly private static ipaddress _ip = ipaddress.parse("37.187.143.226");   //---------sender (client) code--------- _clientsocket = new socket(addressfamily.internetwork, sockettype.stream,     protocoltype.tcp); //connects, no errors appear _clientsocket.connect(ipaddress.parse(_ip), _port);  //sends strings server, no errors appear while (true) {      console.write("enter text send: ");     string input = console.readline();     _clientsocket.send(encoding.ascii.getbytes(input));     console.writeline("sent!"); }  //-------listener (server) code--------      _serversocket = new socket(addressfamily.internetwork, sockettype.stream,     protocoltype.tcp); _serversocket.bind(new ipendpoint(ipaddress.any, _port));  _serversocket.listen(10); console.writeline("waiting client socket connect");     _clientsocket = _serversocket.accept(); //never triggers console.writeline("socket accepted, waiting data..."); 

the server code must run on machine want connect to. machine has ip 37.187.143.226.

so either run locally , use target ip "localhost" or run server on other box , use 37 ip.

also aware firewalls , routers must configured allow access.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -