Severing Orbited javascript connection and reconnecting

25 views
Skip to first unread message

Niklas B

unread,
Aug 10, 2011, 12:55:20 PM8/10/11
to Orbited Discussion
Hi,

Does anyone know how to easily sever the entire connection to Orbited
(or more likely csp/js.io connection), and then re-connect/re-launch
from scratch without without reloading the page? I'm using the irc2.js
protocol, and while I can quit from the client side which kills the
connection, I'm having trouble reconnecting.

Basically the problem appears to be that using quit doesn't sever it
completely (i.e csp/js.io/Orbited tries to send data over the session
that is now invalid. When trying to connect with the TCPSocket again
it gives pretty much random errors. My guess is that the instances are
still available.

I tried resetting the variables Orbited / the TCPSession and then
creating a new instance of them (new TCPSession()) but with no luck,
it just gives me "none callable" errors.

The same code works fine for the first connect.

Regards,
Niklas

Christopher H. Casebeer

unread,
Aug 10, 2011, 4:15:20 PM8/10/11
to orbite...@googlegroups.com
On Aug 10, 2011, at 12:55 PM, Niklas B wrote:
> Does anyone know how to easily sever the entire connection to Orbited
> (or more likely csp/js.io connection), and then re-connect/re-launch
> from scratch without without reloading the page? I'm using the irc2.js
> protocol, and while I can quit from the client side which kills the
> connection, I'm having trouble reconnecting.
>
> Basically the problem appears to be that using quit doesn't sever it
> completely (i.e csp/js.io/Orbited tries to send data over the session
> that is now invalid. When trying to connect with the TCPSocket again
> it gives pretty much random errors. My guess is that the instances are
> still available.

I did a disconnect and reconnect like this under Orbited 0.7 and STOMP by just creating an entirely new STOMPClient object and redoing my STOMPClient event handler setup and connect() call. I called the re-init code in the onerror and onclose handlers, so any protocol issue or explicit close call would cause a clean reconnect.

I seem to remember that the disconnect method didn't allow me to subsequently reconnect, forcing the new object solution, but it's been a while so I'm not sure on that. It also looks like the reset methods on STOMPClient and IRCClient (which call their TCPSocket instances' reset methods) might do what you need, but I can't remember if I tried that. (Again, all Orbited 0.7).

> I tried resetting the variables Orbited / the TCPSession and then
> creating a new instance of them (new TCPSession()) but with no luck,
> it just gives me "none callable" errors.
>

I was originally doing the window.location reload thing, but this turned out not to be necessary. I never had to mess with the window.TCPSocket or any of the other global Orbited objects.

The workaround was for an error with the TCPSocket on the server side (which I can't remember the details of, and no longer have the server side patch to fix), so it seems similar to your problem.

-Chris

--
Christopher Casebeer · http://chc.name
PGP 6a27 e753 b693 6309 f41a 8855 366f cff0 729b a0ee

Niklas B

unread,
Aug 11, 2011, 1:45:02 AM8/11/11
to Orbited Discussion
Yeah,

I think I had more luck with Stomp then IRC oddly enough. I will see
if there might be something odd in the code.

Basically what I am doing is creating a new IRCCLient instance with
all the handles attached which works fine, until I call connect. I
will do more debugging and report back

Thank you,

Btw, you wouldnt also know how to properly compile Orbited.js?
http://groups.google.com/group/jsio/browse_thread/thread/5bce210cb110a2b0

On Aug 10, 10:15 pm, "Christopher H. Casebeer" <caseb...@gmail.com>
wrote:

Niklas B

unread,
Aug 11, 2011, 2:32:21 AM8/11/11
to Orbited Discussion
Here is some more info:

c = new IRCClient()
c.connect('unstable.snyggastchatten.se', 6667)
# Works fine
# closes the conn, just to make sure:
conn.multiplexer.transport._conn.close('')

c2 = new IRCClient()
c2.connect('unstable.snyggastchatten.se', 6667)

TypeError: Cannot call method 'replace' of undefined
at [object Object].connect (jsio/net/csp/client.js:73:19)
at [object Object].connect (jsio/net/env/browser/csp.js:21:8)
at Object.connect (jsio/net.js:18:12)
at [object Object].openStream (jsio/net/protocols/mspp.js:127:8)
at [object Object].open (jsio/net/protocols/mspp.js:52:30)
at [object Object].connect (http://dev.snyggastchatten.se/static/
js/irc2-dev.js:88:14)
at unknown source
at Object._evaluateOn (unknown source)
at Object._evaluateAndWrap (unknown source)
at Object.evaluate (unknown source)

So I guess I'll be digging into CSP/jsio, if I can just figure out how
to properly compile it.


On Aug 11, 7:45 am, Niklas B <biv...@gmail.com> wrote:
> Yeah,
>
> I think I had more luck with Stomp then IRC oddly enough. I will see
> if there might be something odd in the code.
>
> Basically what I am doing is creating a new IRCCLient instance with
> all the handles attached which works fine, until I call connect. I
> will do more debugging and report back
>
> Thank you,
>
> Btw, you wouldnt also know how to properly compile Orbited.js?http://groups.google.com/group/jsio/browse_thread/thread/5bce210cb110...

Niklas B

unread,
Aug 15, 2011, 7:32:47 AM8/15/11
to Orbited Discussion
I've solved my problem. The issue was that when disconnecting a
session the multiplexer (which contains the url variables etc.) is not
removed, just emptied. Thus, the following part of Orbited.js (https://
github.com/mcarter/orbited_08_unofficial/blob/master/orbited/js_src/
Orbited.js):

if (multiplexer == null) {
multiplexer = new MSPPProtocol();
multiplexer.setTransport('csp', {"url": "http://" +
exports.settings.host + ":" + exports.settings.port +
exports.settings.path});
}

Is actually wrong, since multiplexer is still defined but as an empty
variable. Changing it to:

if (multiplexer == null || ('url' in multiplexer) == false ) {
multiplexer = new MSPPProtocol();
multiplexer.setTransport('csp', {"url": "http://" +
exports.settings.host + ":" + exports.settings.port +
exports.settings.path});
}

Solves the issues.
Reply all
Reply to author
Forward
0 new messages