Corrected, I must start by saying that variables with special characters (ç, ã ...) is not at all advised, and with capital in the first letter is also unconventional.
You were also doing two cycles while True:
without any break
in the first, we all know what this results in, when in fact it is only in the last (second) that you need it to be "eternally" running, another thing you can do is use context manager, for "opening sockets" in this way as well as being currently the most advised, also excuses from closing the sockets, such as their use in opening a file:
from socket import*
host = "localhost"
port = 9003
with socket(AF_INET, SOCK_STREAM) as sockobj:
sockobj.bind((host, port))
sockobj.listen(5)
conexao, endereco = sockobj.accept() # esperar ate que cliente se ligue
print('Server conectado por', endereco)
while True:
data = conexao.recv(1024)
if not data:break
Note that when I was testing one of the mistakes you gave me was:
Connectionrefusederror: [Errno 111] Connection refused
This because of the port
which was being used by any other process
Puts the code across sff. What is the error?
– Miguel
This is the code
– user63295
Imports etc... "localhost is not defined", "ame 'AF_INET' is not defined"... etc
– Miguel
Does it lock... by bug or because it is eternally waiting for the customer to send a message? Note that your program handles one connection at a time, and as it stands there waiting, it may be that you just aren’t realizing that the fault is actually in the customer. Note also that your ties are not properly indented.. You have one.
while
infinite just to accept connections! (and, this is probably your problem: your server accepts the first connection, prints the message "connected..." and again accepts connections, getting "apparently" stuck)– Luiz Vieira
Hangs without printing errors? is because the server is working?
– Miguel