Ask coding questions

← Back to all posts
Why python socket client doesn't connect to the server?
OneNose (13)

I am trying to host a python socket server in repl.it. I can connect the server by opening repl.co in my browser but the client does not connect.

The server

import socket

HOST = "0.0.0.0"
PORT = 1080

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print("Connected by", addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(data)

The client

import socket

HOST = "Socket-Test.onenose.repl.co"
PORT = 1080

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(b"MEOW!")
    data = s.recv(1024)

print("Recieved", repr(data))

What am I doing wrong?

Comments
hotnewtop
teidova (0)

I can't connect to my own computer's server either with a client hosted on repl.it :(
Is this broken ?