Hi All,<div><br></div><div> I have run and edited the example provided for txWS. The writing part from server to client browser is shown only as self.transport.write() inside dataReceived function in websockets.py. how do I write on to the socket i.e. on to the browser, from a different function inside server code. The bold point below is where I want to write on to socket. How can we do that? </div>
<div>-------------------------------------------------------</div><div><div>import time</div><div><br></div><div>from twisted.internet import reactor</div><div>from twisted.application import internet</div><div>from twisted.application.service import Application, Service</div>
<div>import xmlrpclib</div><div>from txws import WebSocketFactory</div><div><br></div><div>from src.protocols.websockets import WebSocketServerFactory</div><div>from constants import *</div><div><br></div><div>class WebSocketService(Service):</div>
<div> """</div><div> A simple service that listens on port 8077 for WebSockets traffic.</div><div> """</div><div> def __init__(self):</div><div> self.start_time = time.time()</div>
<div><br></div><div> def start_service(self, application):</div><div> """</div><div> Gets the show on the road. Fires up a factory, binds the port.</div><div> """</div>
<div> echofactory = WebSocketServerFactory(self)</div><div> factory = WebSocketFactory(echofactory)</div><div> ws_server = internet.TCPServer(8077, factory)</div><div> ws_server.setName('ws-tcp')</div>
<div> ws_server.setServiceParent(application)</div><div> ws_server.writeSomeData(self,'abrakadabra..lol')</div><div> </div><div> def shutdown(self):</div><div> """</div><div>
Gracefully shuts down the service.</div><div> """</div><div> reactor.callLater(0, reactor.stop)</div><div><br></div><div>def listDevices(id):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>print "listDevice: %(id)s" % {"id": str(id)} </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>return None</div><div><br></div><div>def event(id, address, key, value):</div><div> #websocket.send("ufffffffffuuuuuu")</div><div><b> #I need to write the below print statement on to browser </b></div>
<div> print "event: %(id)s: %(address)s: %(key)s = %(value)s" % {"id": str(id), </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>"address": str(address), "key": str(key), "value": str(value)}</div>
<div><br></div><div>def aSillyBlockingMethod(x):</div><div> import time</div><div> import xmlrpclib</div><div> time.sleep(2)</div><div> from SimpleXMLRPCServer import SimpleXMLRPCServer</div><div> from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler</div>
<div> from constants import *</div><div> server = SimpleXMLRPCServer((SERVER_IP, SERVER_PORT), logRequests=True, allow_none=True)</div><div> server.register_introspection_functions()</div><div> server.register_multicall_functions()</div>
<div> print "server started at %s" % str(SERVER_URL)</div><div> server.register_function(listDevices)</div><div> server.register_function(event)</div><div> print 'function also got registered'</div>
<div> server.serve_forever()</div><div> .............................continues</div></div><div><br></div><div>Thanks,</div><div>Vinodh</div>