所以我试图用python套接字制作一个小聊天服务器,但我收到了这个错误
File "chatserver.py", line 40
^
SyntaxError: unexpected EOF while parsing
我检查了所有括号等,但不知道这里有什么问题是代码
from socket import *
import logging
import Colorer
CONNECTED = []
HOST = ''
PORT = 9555
s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(2)
def send_message(sock, message):
for socket in CONNECTED:
if socket != s and socket != sock:
try:
socket.send(message)
except:
socket.close()
CONNECTED.remove(socket)
print ("Server Started")
while 1:
connection, addr = s.accept()
if connection:
CONNECTED.append(connection)
print ("Connection from" % addr)
else:
for sock in CONNECTED:
try:
message = sock.recv(1024)
if message:
send_message(sock, str(sock.getpeername() + '<< ' + message))
print (str(sock.getpeername()) + ' ' + message)
如果有人可以帮助我解决这个问题,将不胜感激