Python: Connect via LAN?

Viewed 17998

Just a preface to this question: I have no clue what I am doing, so please excuse any stupidity.

I am making a socket based chatroom that I want to use on a local network (My dad's computer and mine connected through the same wifi).

Here is the server code:

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
sock.listen(1)
while True:
    # Find connections
    connection, client_address = sock.accept()
    try:
        data = connection.recv(999)
        print data

    except:
        connection.close()

Here is the client:

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10000)
print >>sys.stderr, 'connecting to %s port %s' % server_address

while True:
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(server_address)
        message=raw_input('Message: ')
        if message=='quit':
            break
        sock.sendall(message)
    except:
        break
sock.close()

When I run the client on one computer, and the server on the other.. the connection isn't made. I believe it is because of server_address = ('localhost', 10000) but I am not sure.. any suggestions?

1 Answers
Related