c++ - Unable to connect to server (over a remote connection) -
i have been working on project while , wanted test new features on remote connection, client failed connect (while able connect in past). works fine locally. @ moment not able port foward i'm using hamachi. have tried capturing hamachi network traffic wireshark, , client requests arrive, server doesn't receive them.
any appreciated.
code (error checking left out make code more readable):
client:
addrinfo addressinfo, *clientinfo=null; zeromemory(&addressinfo, sizeof(addressinfo)); addressinfo.ai_family = af_inet; addressinfo.ai_socktype = sock_stream; addressinfo.ai_protocol = ipproto_tcp; connectsocket = socket(af_inet, sock_stream, ipproto_tcp); getaddrinfo(strip.c_str(), strport.c_str(), &addressinfo, &clientinfo); connect(connectsocket, clientinfo->ai_addr, clientinfo->ai_addrlen); freeaddrinfo(clientinfo); server:
addrinfo addressinfo, *serverinfo=null; zeromemory(&addressinfo, sizeof(addressinfo)); addressinfo.ai_family = af_inet; addressinfo.ai_socktype = sock_stream; addressinfo.ai_protocol = ipproto_tcp; getaddrinfo(server_ip, server_port, &addressinfo, &serverinfo); listensocket = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); connectionsocket = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); bind(listensocket, serverinfo->ai_addr, serverinfo->ai_addrlen); freeaddrinfo(serverinfo); listen( listensocket, somaxconn ) while(true) { if(connectionsocket = accept(listensocket, null, null)) { //do stuff } }
i not know how abridged code you've pasted but:
1) there no place set destination address 2) there no place set destination port 3) port server trying bind? ...so cannot work @ all. please handle errors - (yes said you've omitted them on purpose) bet if server refuses connection error handling shows that. otherwise connects fine claim otherwise. say:
1) 'the client failed connect' 2) , later 'the client requests arrive, server doesn't receive them' if able connect - should see 3 way handshake (tcp stream connection). if not error handling , wireshark show that. client requests arrive code not sending (no sending code available). server not receive them - if connects , send there no way error handling shows nothing , server receives nothing (but server code lacks receive routine call).
i think right cannot receive that. update code, verify if works locally (you mean loopback here right?), test 'not locally', add error handling , use wireshark on both client , server side.
Comments
Post a Comment