[Twisted-Python] connecting with a FlashXML socket

hey All, my friend and i are attempting to use twisted as a socket server to be able to accept connections from a flash client. here is the simple connection code on the serverside: from twisted.protocols import basic class TestApp(basic.LineReceiver): def connectionMade(self): print "new client\n" self.factory.clients.append(self) self.message("test") self.sendLine("another test"); def connectionLost(self): print "lost client\n" self.factory.clients.remove(self) def lineReceived(self,line): print "recieved:", repr(line) for c in self.factory.clients: c.message(line) def message(self,msg): self.transport.write(msg + '\n') print msg + '\n' this is basically the same as an example we were using to help us get the code going. but when we run the server, and then go to the client... the client connects fine, but we cannt send/recieve any messages. we tried setting the self.delimiter = "\0" since that is a requirement for flashXML, but it still wouldnt send/recieve. the socket code on the flash-side is relative to the following: mySocket = new XMLSocket(); mySocket.onConnect = function(success) { if (success) msgArea.htmlText += ";<b>Server connection established!</b>" else msgArea.htmlText += "<b>Server connection failed!</b>" } mySocket.onClose = function() { msgArea.htmlText += "<b>Server connection lost</b>" } XMLSocket.prototype.onData = function(msg) { trace("MSG: " + msg) msgArea.htmlText += msg } mySocket.connect("localhost", 9999) function sendMsg() { mySocket.send(inputMsg.htmlText + "\n") } } __________________________________ Do you Yahoo!? Yahoo! Small Business - Try our new resources site! http://smallbusiness.yahoo.com/resources/

i use a \x00 as a terminator.... this script below has an other class changhandler that looks if there is a new file in directory and sends that file (xml) to all connected clients... it's used for a web radio to push the meta infos to the clients. have fun from twisted.internet.protocol import Factory, Protocol from twisted.internet import reactor from xml.dom.minidom import parseString import changehandler class Radio(Protocol): def connectionMade(self): self.factory.clients.append(self) self.transport.write(self.factory.msg) self.ip=self.transport.getHost().host print self.ip+' connected' def dataReceived(self, data): print data try: doc=parseString(data[0:-1]) if doc.nodeName == 'connect': if doc.attributes.has_key('service'): self.service=doc.attributes['service']._value print "new service"+self.sevice else: print "connect was malformatted" else: pass except: print "parsing error" def connectionLost(self, reason='connectionDone'): print self.ip+' disconnected' class XMLSocket(Factory): clients=[] msg='<hello>world</hello>\x00' protocol = Radio services = [["radio",Radio]] def __init__(self, protocol=None): self.protocol=protocol reactor.callLater(0,self.sendMsg) def sendMsg(self): msg=changehandler.waiting() if msg: for client in self.clients: client.transport.write(msg+"\x00") reactor.callLater(0,self.sendMsg) reactor.listenTCP(8000, XMLSocket(Radio)) reactor.run()
participants (2)
-
Eric T
-
Patrick Lauber