hello.
I recently started to learn python and I keep having the same problem in the socket programming section.
I run the same codes in a youtube video that I on my spyder. I followed exact intructions but I cant continue because kernel keep giving me red error.
here are codes
#server.py
import socket
import threading
PORT = 5050
SERVER = socket.gethostbyname(socket.gethostname())
ADDR = (SERVER,PORT)
HEADER = 64
FORMAT = "utf-8"
DISCONNECT_MESSAGE ="DISCONNECT!"
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(ADDR)
def handle_client(conn,addr):
print(f"NEW CONNECTİON {addr} connected")
connected = True
while connected:
msg.length = conn.recv(HEADER).decode(FORMAT)
msg.length = int(msg.length)
msg = conn.recv(msg.length).decode(FORMAT)
if msg == DISCONNECT_MESSAGE:
connected = False
print(f"[{addr}] {msg}")
#conn.close()
def start():
server.listen()
print(f"[LISTENING] server is listening on {SERVER}")
conn, addr = server.accept()
thread= threading.Thread(target=handle_client, args=(conn, addr))
thread.start()
print(f"[ACTİVE CONNECTİONS] {threading.activeCount()-1}")
the output