JadedTuna
JadedTuna

Reputation: 1823

Python can't connect to open socket on the same network

I have started a simple python socket, and I can freely connect to it from my local computer, but from iPad and another computer, I can't access it! What I am doing wrong? Here is my code:

from socket import socket

server = socket()
server.bind(("", 80))
server.listen(2)
message = """\
</pre><br><br><h1>Hi!</h1></body></html>
"""

while 1:
    c, a = server.accept()
    print "New connection from %s:%s"%tuple(a)
    c.sendall("<html><head><title>Hi!</title></head><body><pre>"+c.recv(4096*20)+message)
    c.close()

EDIT

Btw, I am using Linux Fedora 18. On Windows, I didn't have problems with sockets.

Upvotes: 2

Views: 2545

Answers (1)

Doug T.
Doug T.

Reputation: 65589

In the docs on socket:

If supplied, source_address must be a 2-tuple (host, port) for the socket to bind to as its source address before connecting. If host or port are ‘’ or 0 respectively the OS default behavior will be used.

The default behavior is likely to host on localhost. Try setting host to "0.0.0.0" to allow connectivity outside localhost.

Upvotes: 2

Related Questions