0
我有2个服务器文件工作与电晕模拟器。一个是工作,但另一个不是。不知道这两个文件有什么不同。以下是我的服务器代码。电晕模拟器连接到服务器后停止工作
非工作:
class Chat(Protocol):
def connectionMade(self):
self.factory.clients.append(self)
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self,data):
for c in self.factory.clients:
c.message(data)
print data
def message(self, data):
self.transport.write(data)
factory = Factory()
factory.clients = []
factory.protocol = Chat
reactor.listenTCP(8080,factory)
reactor.run()
工作:
class IphoneChat(Protocol):
def connectionMade(self):
self.factory.clients.append(self)
print "Clients are " ,self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
print "The data is " ,data
for c in self.factory.clients:
c.message(data)
def message(self, message):
self.transport.write(message + '\n')
factory = Factory()
factory.clients = []
factory.protocol = IphoneChat
reactor.listenTCP(8080, factory)
print "Server Start!!!"
reactor.run()
我把我所有的代码,因为我怕失去了一些东西有关代码重要的。 谢谢你的帮助。
我只知道。非常感谢你。 :D – user3480543 2014-09-06 16:33:33
嗨iBad,我尝试使用Ruby服务器而不是Python。红宝石有这样的要求吗?我使用了“aaa”,但似乎有同样的问题。 – user3480543 2014-09-07 02:06:34
嗨,它的协议要求,不依赖于语言。电晕客户端只是坐在那里,等待'\ n' – iBad 2014-09-07 05:32:34