<div class="gmail_quote">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(server.tac). I&#39;m just starting another xmlrpc server on a thread where I receive some notifications. I need to forward the same to socket. The bold point below  is where I want to write on to socket. How can we do that? Please help me out.</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>    &quot;&quot;&quot;</div><div>    A simple service that listens on port 8077 for WebSockets traffic.</div><div>    &quot;&quot;&quot;</div><div>    def __init__(self):</div><div>        self.start_time = time.time()</div>

<div><br></div><div>    def start_service(self, application):</div><div>        &quot;&quot;&quot;</div><div>        Gets the show on the road. Fires up a factory, binds the port.</div><div>        &quot;&quot;&quot;</div>

<div>        echofactory = WebSocketServerFactory(self)</div><div>        factory = WebSocketFactory(echofactory)</div><div>        ws_server = internet.TCPServer(8077, factory)</div><div>        ws_server.setName(&#39;ws-tcp&#39;)</div>

<div>        ws_server.setServiceParent(application)</div><div>   </div><div>    def shutdown(self):</div><div>        &quot;&quot;&quot;</div><div>
        Gracefully shuts down the service.</div><div>        &quot;&quot;&quot;</div><div>        reactor.callLater(0, reactor.stop)</div><div><br></div><div>def listDevices(id):</div><div><span style="white-space:pre-wrap">        </span>print &quot;listDevice: %(id)s&quot; % {&quot;id&quot;: str(id)} </div>

<div><span style="white-space:pre-wrap">        </span>return None</div><div><br></div><div>def event(id, address, key, value):</div><div>        #websocket.send(&quot;ufffffffffuuuuuu&quot;)</div><div><b>        #I need to write the below print statement on to browser </b></div>

<div>        print &quot;event: %(id)s: %(address)s: %(key)s = %(value)s&quot; % {&quot;id&quot;: str(id), </div><div><span style="white-space:pre-wrap">                        </span>&quot;address&quot;: str(address), &quot;key&quot;: str(key), &quot;value&quot;: 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 &quot;server started at %s&quot; % str(SERVER_URL)</div><div>    server.register_function(listDevices)</div><div>    server.register_function(event)</div><div>    print &#39;function also got registered&#39;</div>

<div>    server.serve_forever()</div><div>    .............................continues</div></div><div><br></div><div>Thanks,</div><div>Vinodh</div>
</div><br>