I have 2 server file work with corona simulator. One is work but another isn't. Not sure what is the different between these 2 file. Below is my server code.
Non-working:
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()
Working:
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()
I put all of my code because I afraid of missing something important about the code. Thank you for incoming help.