The issue is that your indentation is incorrect. By indentation I mean
Leading whitespace (spaces and tabs) at the beginning of a logical
line is used to compute the indentation level of the line, which in
turn is used to determine the grouping of statements
This link is helpful for you to see why indentation is important.
To fix this, format the code with an IDE. You can use this code instead, I have fixed indentation for you.
import socket
import sys
from _thread import *
host=""
port = 5555
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((host, port))
except socket.error as e:
print(str(e))
s.listen(5)
print ('waiting for a connection')
def threaded_client(conn):
conn.send(str.encode('Welcome, type your info\n'))
while True:
data = conn.recv(2048)
reply = 'Server output: ' +data.decode('utf-8')
if not data:
break
conn.sendall(str.encode(reply))
conn.close()
while True:
conn, addr = s.accept()
print('connected to: '+addr[0]+':'+str(addr[1]))
start_new_thread(threaded_client, (conn,))
0
solved python while true wierd error [closed]