Re: How to disconnect client using Autobahn websocket server

2,750 views
Skip to first unread message

Rigaudie François

unread,
Sep 9, 2012, 7:51:36 AM9/9/12
to autob...@googlegroups.com

hi rizwan,
one possibility is to implement a rpc on client side that will call the socket close() and trigger it from server side. but it is not the best thing to do, I agree, executing it from server directly would be better.
françois

Le 8 sept. 2012 23:20, "Rizwan" <djri...@gmail.com> a écrit :
Hi, i am using the example of autobahn websocket server in python.
now as a client in javascript, one can disconnect the socket using socket.close(), however if one wants to disconnect connected client from the server how can this be done??

Tobias Oberstein

unread,
Sep 9, 2012, 1:40:47 PM9/9/12
to autob...@googlegroups.com, Rizwan
Am 08.09.2012 23:20, schrieb Rizwan:
> Hi, i am using the example of autobahn websocket server in python.
> now as a client in javascript, one can disconnect the socket using
> socket.close(), however if one wants to disconnect connected client from
> the server how can this be done??

just call

def sendClose(self, code = None, reason = None)

available on WebSocketServerProtocol and WebSocketClientProtocol

will start closing handshake .. exactly as browser.

Cheers,
Tobias

Keen

unread,
Sep 13, 2012, 5:18:47 AM9/13/12
to autob...@googlegroups.com, Rizwan
It's hard to use autobahnPython for me , I don't konw how to use the pamas code and reason, I need a example. Sorry~~~ but thanks a lot!

在 2012年9月10日星期一UTC+8上午1时40分50秒,Tobias Oberstein写道:

Kevin Helton

unread,
Oct 23, 2013, 7:35:10 PM10/23/13
to autob...@googlegroups.com, Rizwan
Hi Tobias,

Can you elaborate a bit or maybe provide a simple example. I have a broadcast server with multiple possible clients and am looking to target specific connects to close based on a response from the client. Really, I'm trying to do a simple password(pin) authentication and close connections that do not have the proper password. Any help will be appreciated!

Kevin

Tobias Oberstein

unread,
Oct 25, 2013, 5:26:29 AM10/25/13
to autob...@googlegroups.com, Rizwan
Kevin,

not sure what you exactly a trying to do:

"response from client": the broadcast server does not receive responses, but just dispatches anything it receives to all currently connected clients.

Usually, a "response" is something a peer sends upon a "request" .. that would be a "Request/Response" pattern. You might have a look at the WAMP examples that come with AutobahnPython. Those provide "Remote Procedure Calls" (= Request/Response) and PubSub. They also show how to do authentication. And WAMP also allows you to target specific clients, since WAMP assign unique session IDs to clients (which is needed, at least when referring a session from a different session).

Of course you could reinvent parts of WAMP on your own .. however, I'd not recommend that, but instead first look if WAMP already provides what you need. If so, that'll much quicker for you, and you also profit from the work done on WAMP now and in the future.

/Tobias

Kevin Helton

unread,
Oct 27, 2013, 12:19:29 AM10/27/13
to autob...@googlegroups.com, Rizwan
Thanks Tobias, I'll take a look and give it a go!

Tom Sheffler

unread,
Oct 27, 2013, 2:52:22 PM10/27/13
to autob...@googlegroups.com, Rizwan
There is also a way to unceremoniously drop a connection:  it will look something like this:

class MyWebSocket(WebSocketServerProtocol):

  def unceremoniouslyKillClient(self):
    self.transport.loseConnection()

This doesn't shut down the websocket protocol, it just loses the tcp conneciton.
Reply all
Reply to author
Forward
0 new messages