I have a list related to multiclient chat server problem. This is the list ['talk', client_n, message]. How can I send 'message' to 'client_n' from the server in twisted python using transport.write()?
I wrote the code in two ways. But both are not working.
1st way:
data = data.strip()
dat1 = data.split()
dat2 = ' '.join(dat1)
l = dat2[5:12]
m = dat2[13:]
l.transport.write(m)
2nd way:
data = data.strip()
dat1 = data.split()
l1 = dat1[1]
m1 = dat1[2]
if l1 in self.factory.clients:
l1.transport.write(m1)
But in both I got attribute error.
exceptions.AttributeError: 'str' object has no attribute 'transport'
Can anybody give me a solution for this, please?
What is self.factory.clients? Is it perhaps a dictionary? Do you really want to do something like:
client = self.factory.clients.get(client_n)
if client:
client.transport.write(message)
我不是专家,但也许您应该考虑通过JSON序列化和反序列化您的列表?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.