I create a simply client and a server using python. In order to create my server I do a port forwarding. But I have a problem that I don't success to resolve, in fact no matter if the server is online or offline. My socket gives me a message of success. Where does this failure come from ?
This is my code in the client:
from threading import Thread
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Client connection success"
print "Client error"
msg = raw_input("Client:")
response_server = client_socket.recv(1024)
send_thread = Thread(target=send_to_server,)
recv_thread = Thread(target=recv_from_server,)
if __name__ == "__main__":
As you are connecting to the intermediate node using socket which in turn forwarding you request to target node in the same network, the connection to your intermediate node will be successful even if your target node is down.
So since your client's
client_socket.connect() won't be informed about whether the socket connection to target node from intermediate node was successful or not, it will always return success as it was successfully connected to the intermediate node.
But a simple hack to find out whether you were actually connected to target node would be to check whether you are actually receiving the expected response within a specified amount of time after sending the request (Assuming that for every request being sent by client, the server will be sending some response).