import threading, time, socket
def ProcessMessage(m, conn):
prefix = m[:4]
if prefix == '/msg':
print "message: ", m[4:]
conn.send(m[4:])
elif prefix == '/dsc':
print "disconnect"
conn.close()
class Connection():
def __init__(self, id):
self.id = id
def disconnect(self):
self.id.close()
pm = ProcessMessage
class ServerThread(threading.Thread):
def __init__(self, channel, details):
self.channel = channel
self.details = details
threading.Thread.__init__(self)
client = Connection(self.channel)
def run(self):
print 'Connection from:', self.details[0]
while True:
client.pm(self.channel.recv(255), self.channel)
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 3333))
server.listen(5)
while True:
channel, details = server.accept()
ServerThread(channel, details).start()
Пытаюсь написать примитивный чат.
Скажите, почему python ругается на «client = Connection(self.channel)»?
Спасибо.
P.S. python не знаю, пишу параллельно со чтением доков.