1

I'm trying to make a TCP chat on port 10 000, I have a linux server on which I'm listening :

NETSTAT report :

tcp        0      0 127.0.0.1:10000         0.0.0.0:*               LISTEN

NMAP report :

10000/tcp open  snet-sensor-mgmt

But I can not seem to get a connection when trying to reach out to the server from my home computer with the following code:

def sock_connect (server,port) :
    # Create a TCP/IP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # Connect the socket to the port where the server is listening
    server_address = (server,port)
    print ('[+] Connecting to %s ...' % server)
    sock.connect(server_address)
    print('[+] Successfully connected to %s' % server)
    return(sock)

Please note, it all works perfectly on my localhost. I have allowed all port 10000 incoming traffic on my server but I have no portforwarded or configurated anything on my home router, could that be the problem ?

Thanks in advance for your help!

Tim
  • 394
  • 2
  • 14
  • Yes, this should related to your firewall and not to a python error. – Pedro Lobito Dec 14 '18 at 09:24
  • Can you try changing the local listening address from 127.0.0.1 to the actual IP address of the server? I'm not sure this is actually related to python issues. – caterpree Dec 14 '18 at 09:25
  • Instead of listen `127.0.0.1:10000`, try listen `0.0.0.0:10000` – Xiwei Wang Dec 14 '18 at 09:26
  • Looks like it works with 0.0.0.0 ! Thank you a lot ! Any insight on the difference between listening to localhost and 0.0.0.0 ? Thanks !! – Tim Dec 14 '18 at 10:02
  • The connection is not coming to the 127.0.0.1 address from the outside world, therefore it won't be able to connect to it, only the "localhost" can connect to 127.0.0.1, it's not accessible from outside the server. – caterpree Dec 14 '18 at 10:17
  • @guillottim You can get more information at https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1 – Xiwei Wang Dec 14 '18 at 10:28

1 Answers1

0

Like Xiwei Wang commented, the solution was to listen on 0.0.0.0 Thanks again !

Tim
  • 394
  • 2
  • 14