Search code examples
pythonsocketsclient

Making Python sockets visible for outside world


It seems nothing is wrong with my network setup, however other software can be seen from the outside (netcat listen servers etc.) but not my scripts. How can this be?

It works on LAN but not over the internet.

Server:

import socket

host = ''
port = 80001

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(1)
print 'Listening..'
conn, addr = s.accept()
print 'is up and running.'
print addr, 'connected.'
s.close()
print 'shut down.'

Client:

import socket
host = '80.xxx.xxx.xxx'
port = 80001

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
s.close()

Solution

  • In your server script you have port = 80, but you don't ever use it. It looks like the server is listening on 63001. And the client is connecting to 80.

    If you're going to use 80, make sure you don't have an http server trying to use the port at the same time as well.