连接到服务器后,Corona Simulator停止工作 [英] Corona Simulator stop working after connecting to server

查看:102
本文介绍了连接到服务器后,Corona Simulator停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个与电晕模拟器一起使用的服务器文件.一个是工作,但另一个不是.不确定这2个文件之间有什么区别.下面是我的服务器代码.

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.

不工作:

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()

我放置了所有代码,因为我害怕遗漏一些与代码有关的重要信息. 谢谢您的帮助.

I put all of my code because I afraid of missing something important about the code. Thank you for incoming help.

推荐答案

您需要在邮件末尾发送"\ n"

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()

它的HTTP协议要求.

Its HTTP protocol requirement.

这篇关于连接到服务器后,Corona Simulator停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆