22209

Corona Simulator stop working after connecting to server

Question:

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.

Answer1:

You need to send "\n" at the end of message

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 + '\n') factory = Factory() factory.clients = [] factory.protocol = Chat reactor.listenTCP(8080,factory) reactor.run()

Its HTTP protocol requirement.

Recommend

  • Multi-group chat server in python twisted [closed]
  • Reconnect to different address in twisted?
  • Detect bluetooth device disconnected
  • Maximum BackStack size in android
  • ngOnChanges not firing when attribute changed by Observable/subscrption
  • Request response issues in biztalk
  • Doctrine2 bulk import try to work with another entity
  • Using Sax parsing to edit and write XML in VB6
  • Run multiple queries from 1 SQL file showing result in multiple tables
  • wxPython: displaying multiple widgets in same frame
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Debug.DrawLine not showing in the GameView
  • SplFileObject error failed to open stream: No such file or directory
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Yii2: Config params vs. const/define
  • How do I change content of ComboFieldEditor?
  • How can I send an e-mail from a vbs script
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Counter field in MS Access, how to generate?
  • Accessing IRQ description array within a module and displaying action names
  • Is there a amazon webstore API for customers?
  • Can Jackson SerializationFeature be overridden per field or class?
  • How to extract text from Word files using C#?
  • vba code to select only visible cells in specific column except heading
  • How can I use Kendo UI with Razor?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Return words with double consecutive letters
  • How to delete a row from a dynamic generate table using jquery?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • KeystoneJS: Relationships in Admin UI not updating
  • trying to dynamically update Highchart column chart but series undefined
  • Getting Messege Twice Using IMvxMessenger
  • embed rChart in Markdown
  • Is there any way to bind data to data.frame by some index?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Reading document lines to the user (python)
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • Python/Django TangoWithDjango Models and Databases