sendClose() ?

#1

I was a question on StackOverflow yesterday about calling sendClose() to select clients from a router. I was going to try to answer that question but I couldn’t figure it out.

I took one of the basicrouter.py routers from the twisted examples. I used onJoin and onLeave to record the active sessions for this router. I then created a ‘adm.session.list’ rpc call to collect that data. When called, I return json with the session_id, authid, and the actual session (self) for the client.

I thought it would be a simple matter at this point to add another rpc call:

adm.session.kill

where I pass the session id and then kill the session. I can’t kill it. I saw an answer on SO indicating that sendClose() can be called from the WebSocketServerProtocol. How do I reference that? Most of he imports I do are from the wamp side of the fence. In the router main, I see:

I’ve attached the basicrouter.py code I was working with. How can I close the session from the router?

-g

basicrouter.py (9.93 KB)

0 Likes

#2

More information on this. I changed my basicrouter.py command to close the client, and that seems to work. When the client connects I record its sessionid/session, then I created a message called adm.session.kill(sessionid) which recalls the session for the client and runs:

ses._transport.close()

This definitely closes the connection.

I tried to send information to the client about the close, I tried:

ses._transport.close(reason=‘killed’)

close reason without close code

ses._transport.close(reason=‘killed’, code=3000)

and I get

invalid type <type ‘str’> for close reason

dug through the code a bit, and I see that ‘six’ is wanted for the reason type:

if type(reason) != six.text_type:

raise Exception(“invalid type %s for close reason” % type(reason))

So I changed that:

import six

ses._transport.close(reason=six.u(‘killed’), code=3000)

So that works, when I look at the verbose output of the session that was just killed:

onLeave: CloseDetails(reason = None, message = ‘None’’)

Which was produced by this:

def onLeave(self, details):

print(“onLeave: {}”.format(details))

Which leads me to my question about sendClose(). I think I got it to work, but, I could have very well been calling the wrong thing. Is this the right way to kill a session? If so is it useful to use a reason and a code? Finally, it doesn’t matter what I put after the onLeave print statement, I cannot get the client to exit. I’ve tried reactor.stop(), self.disconnect(), self.close(), etc… Nothing seems to work. I tried sys.exit(42), that didn’t work. os._exit(42) worked, but, that’s over the top.

-g

0 Likes

#3

Hi Greg,

I was a question on StackOverflow yesterday about calling sendClose() to
select clients from a router. I was going to try to answer that

sendClose() is a WebSocket transport specific method. You would only be able to "close" WAMP clients that connect over WebSocket, not over RawSocket or other transports.

question but I couldn't figure it out.

I took one of the basicrouter.py routers from the twisted examples. I
used onJoin and onLeave to record the active sessions for this router.
  I then created a 'adm.session.list' rpc call to collect that data.
  When called, I return json with the session_id, authid, and the actual
session (self) for the client.

I thought it would be a simple matter at this point to add another rpc call:

adm.session.kill

where I pass the session id and then kill the session. I can't kill it.
   I saw an answer on SO indicating that sendClose() can be called from
the WebSocketServerProtocol. How do I reference that? Most of he

Not sure if we saw the same SO question, but as I understood, the answer on SO was for a developer that was using AutobahnPython as a mere _WebSocket_ library - not WAMP.

imports I do are from the wamp side of the fence. In the router main,
I see:

I've attached the basicrouter.py code I was working with. How can I
close the session from the router?

Are you trying to write a custom router?

What would be the trigger for closing a WAMP session?

Cheers,
/Tobias

···

Am 08.09.2014 15:19, schrieb Greg Fausak:

-g

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
To post to this group, send email to autob...@googlegroups.com
<mailto:autob...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com
<https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#4

Tobias,

I am working on a customer Router. However, the question I’m asking here is simply academic. How can I kill a session from the router. I am porting an application from v1 to v2. One of the functions in my ‘router’ on v1 was a sweeper that kicked off all idle users. In v2 I did a sendClose() and that closed the connection from the Router side. I’m just trying to match that functionality so that I can get off v1 and switch completely to v2. I’m pretty close, I’ve been working on it for 2 weeks now.

Thanks,

-g

···

On Thursday, September 11, 2014 3:27:29 AM UTC-5, Tobias Oberstein wrote:

Hi Greg,

Am 08.09.2014 15:19, schrieb Greg Fausak:

I was a question on StackOverflow yesterday about calling sendClose() to

select clients from a router. I was going to try to answer that

sendClose() is a WebSocket transport specific method. You would only be
able to “close” WAMP clients that connect over WebSocket, not over
RawSocket or other transports.

question but I couldn’t figure it out.

I took one of the basicrouter.py routers from the twisted examples. I

used onJoin and onLeave to record the active sessions for this router.

I then created a ‘adm.session.list’ rpc call to collect that data.

When called, I return json with the session_id, authid, and the actual

session (self) for the client.

I thought it would be a simple matter at this point to add another rpc call:

adm.session.kill

where I pass the session id and then kill the session. I can’t kill it.

I saw an answer on SO indicating that sendClose() can be called from

the WebSocketServerProtocol. How do I reference that? Most of he

Not sure if we saw the same SO question, but as I understood, the answer
on SO was for a developer that was using AutobahnPython as a mere
WebSocket library - not WAMP.

imports I do are from the wamp side of the fence. In the router main,

I see:

I’ve attached the basicrouter.py code I was working with. How can I

close the session from the router?

Are you trying to write a custom router?

What would be the trigger for closing a WAMP session?

Cheers,

/Tobias

-g

You received this message because you are subscribed to the Google

Groups “Autobahn” group.

To unsubscribe from this group and stop receiving emails from it, send

an email to autobahnws+...@googlegroups.com

mailto:autobahnws+unsub...@googlegroups.com.

To post to this group, send email to auto...@googlegroups.com

mailto:autob...@googlegroups.com.

To view this discussion on the web visit

https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com

<https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com?utm_medium=email&utm_source=footer>.

For more options, visit https://groups.google.com/d/optout.

0 Likes

#5

Tobias,

I am working on a customer Router. However, the question I'm asking
here is simply academic. How can I kill a session from the router. I am
porting an application from v1 to v2. One of the functions in my

In principle, this should be done by calling leave() or disconnect() on the RouterSession.

Seems like I missed to implement the latter (while the former is there):

https://github.com/tavendo/AutobahnPython/issues/269

For now, you can close the underlying transport by doing

RouterSession._transport.close()
RouterSession._transport.abort()

However, this accesses the internal member variable _transport.

The _transport is a WAMP transport, and that instance implements

http://autobahn.ws/python/reference/autobahn.wamp.html#autobahn.wamp.interfaces.ITransport

Here you also find documentation on close() and abort()

'router' on v1 was a sweeper that kicked off all idle users. In v2 I
did a sendClose() and that closed the connection from the Router side.
  I'm just trying to match that functionality so that I can get off v1
and switch completely to v2. I'm pretty close, I've been working on it

sendClose() is WebSocket specific. Hence ITransport.close() and ITransport.abort() - which are abstract transport methods (means, it'll work for transports other than WebSocket also).

Hope this helps. Let me know if I now confused you or you have more questions ..

Cheers,
/Tobias

···

Am 11.09.2014 16:03, schrieb Greg Fausak:

for 2 weeks now.

Thanks,
-g

On Thursday, September 11, 2014 3:27:29 AM UTC-5, Tobias Oberstein wrote:

    Hi Greg,

    Am 08.09.2014 15:19, schrieb Greg Fausak:
     > I was a question on StackOverflow yesterday about calling
    sendClose() to
     > select clients from a router. I was going to try to answer that

    sendClose() is a WebSocket transport specific method. You would only be
    able to "close" WAMP clients that connect over WebSocket, not over
    RawSocket or other transports.

     > question but I couldn't figure it out.
     >
     > I took one of the basicrouter.py routers from the twisted
    examples. I
     > used onJoin and onLeave to record the active sessions for this
    router.
     > I then created a 'adm.session.list' rpc call to collect that data.
     > When called, I return json with the session_id, authid, and the
    actual
     > session (self) for the client.
     >
     > I thought it would be a simple matter at this point to add
    another rpc call:
     >
     > adm.session.kill
     >
     > where I pass the session id and then kill the session. I can't
    kill it.
     > I saw an answer on SO indicating that sendClose() can be
    called from
     > the WebSocketServerProtocol. How do I reference that? Most of he

    Not sure if we saw the same SO question, but as I understood, the
    answer
    on SO was for a developer that was using AutobahnPython as a mere
    _WebSocket_ library - not WAMP.

     > imports I do are from the wamp side of the fence. In the router
    main,
     > I see:
     >
     > I've attached the basicrouter.py code I was working with. How can I
     > close the session from the router?

    Are you trying to write a custom router?

    What would be the trigger for closing a WAMP session?

    Cheers,
    /Tobias

     >
     > -g
     >
     > --
     > You received this message because you are subscribed to the Google
     > Groups "Autobahn" group.
     > To unsubscribe from this group and stop receiving emails from it,
    send
     > an email to autobah...@googlegroups.com <javascript:>
     > <mailto:autobahnws+...@googlegroups.com <javascript:>>.
     > To post to this group, send email to auto...@googlegroups.com
    <javascript:>
     > <mailto:auto...@googlegroups.com <javascript:>>.
     > To view this discussion on the web visit
     >
    https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com
    <https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com>

     >
    <https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com?utm_medium=email&utm_source=footer
    <https://groups.google.com/d/msgid/autobahnws/d8c1677b-621c-4e26-bf81-662cbff5b5fd%40googlegroups.com?utm_medium=email&utm_source=footer>>.

     > For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
To post to this group, send email to autob...@googlegroups.com
<mailto:autob...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/autobahnws/2118dadf-4189-4bbe-afc5-d07604b88318%40googlegroups.com
<https://groups.google.com/d/msgid/autobahnws/2118dadf-4189-4bbe-afc5-d07604b88318%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

0 Likes