Close a Longpoll Connection Using JS

33 views
Skip to first unread message

Rob Carlo

unread,
Nov 29, 2017, 11:34:46 AM11/29/17
to nginxpushstream
My entire site is ajax loaded and I need to be able to close a long poll connection, add or remove a channel and then begin the long poll again. Is there a way to do this or even a better way all together? Currently I use a channel for the users profileid and would like to pass a few others depending on what page they are on.

Thanks,
Rob

Wandenberg Peixoto

unread,
Nov 30, 2017, 5:29:30 AM11/30/17
to nginxpu...@googlegroups.com
Hi Rob,

not sure if I understand your question. It will depend on how you are opening the request to the server. If you are using xhr or a "script" tag, for instance.
You can try to call "abort" or "close" in your connection object. Take a look at the pushstream.js code or use it as a client if you prefer.
You can subscribe multiple channels in the same connection, but you can't add channels to a previous connection, so you need to disconnect an connect again, with the new channels list, or open a second connection, which I don't recommend for performance reasons.


--
You received this message because you are subscribed to the Google Groups "nginxpushstream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginxpushstream+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Carlo

unread,
Nov 30, 2017, 12:41:11 PM11/30/17
to nginxpu...@googlegroups.com
I'm calling this function a few seconds after my initial page loads and the script is auto reconnecting so I'm not actually making the AJAX call directly.

var ps;
function startLongPoll() {

ps = new PushStream({
host: dev+'lp-s1.snipbo.com',
port: 443,
useSSL:true,
useJSONP:true,
modes: "longpolling",
messagesControlByArgument: true
});
ps.onmessage = longPollReceived;
ps.addChannel(dev+'p'+PID);
ps.connect();
}

Thanks,
Rob

--
You received this message because you are subscribed to a topic in the Google Groups "nginxpushstream" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nginxpushstream/OK9_rwX-LDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nginxpushstream+unsubscribe@googlegroups.com.

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



--


Rob Carlo
Founder & Lead Developer, Snipbo.com
A better way to share, sell and be socially organized

Phone | Text: (316) 312-9465
Email: r...@snipbo.com
Skype: rob.carlo

 
 

Wandenberg Peixoto

unread,
Nov 30, 2017, 3:20:14 PM11/30/17
to nginxpu...@googlegroups.com
So, to add a new channel (or remove) it is enough to do like "ps.addChannel('new_channel');" in any other moment in your code that has access to the "ps" variable.
The addChannel function already takes care of disconnect and connect again when the client is connected.
If you want to add more than one channel my recommendation then would be like this
ps.disconnect();
ps.addChannel('ch1');
ps.addChannel('ch2');
...
ps.addChannel('chN');
ps.connect();

Avoiding a reconnection on each call to addChannel.

Hope that this helps you.

r...@snipbo.com

unread,
Nov 30, 2017, 3:38:10 PM11/30/17
to nginxpu...@googlegroups.com
Nailed it!!!!! That's exactly what I was looking for. Thank You!!!
 
 
  
 
 
--------- Original Message ---------
To unsubscribe from this group and stop receiving emails from it, send an email to nginxpushstre...@googlegroups.com.

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

 

--
You received this message because you are subscribed to a topic in the Google Groups "nginxpushstream" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nginxpushstream/OK9_rwX-LDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nginxpushstre...@googlegroups.com.

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


 
--


Rob Carlo
Founder & Lead Developer, Snipbo.com
A better way to share, sell and be socially organized

Phone | Text: (316) 312-9465
Email: r...@snipbo.com
Skype: rob.carlo

 
 

 

--
You received this message because you are subscribed to the Google Groups "nginxpushstream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginxpushstre...@googlegroups.com.

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

 

--
You received this message because you are subscribed to a topic in the Google Groups "nginxpushstream" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nginxpushstream/OK9_rwX-LDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nginxpushstre...@googlegroups.com.

Rob Carlo

unread,
Dec 6, 2017, 6:40:04 PM12/6/17
to nginxpushstream
When I do this it adds another longpoll connection and doesn't release the previous until it times out. Is there a way I can fix this? Just hacking at the code someone would be able to open tons of connections. They would all drop off as they timeout but is there a way around this?

--------- Original Message ---------
To unsubscribe from this group and stop receiving emails from it, send an email to nginxpushstream+unsubscribe@googlegroups.com.

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

 

--
You received this message because you are subscribed to a topic in the Google Groups "nginxpushstream" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nginxpushstream/OK9_rwX-LDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nginxpushstream+unsubscribe@googlegroups.com.

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


 
--


Rob Carlo
Founder & Lead Developer, Snipbo.com
A better way to share, sell and be socially organized

Phone | Text: (316) 312-9465
Email: r...@snipbo.com
Skype: rob.carlo

 
 

 

--
You received this message because you are subscribed to the Google Groups "nginxpushstream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginxpushstream+unsubscribe@googlegroups.com.

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

 

--
You received this message because you are subscribed to a topic in the Google Groups "nginxpushstream" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nginxpushstream/OK9_rwX-LDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nginxpushstream+unsubscribe@googlegroups.com.

Wandenberg Peixoto

unread,
Dec 6, 2017, 7:54:19 PM12/6/17
to nginxpu...@googlegroups.com
Not sure if I understood the problem, but when you disconnect on the client side, not necessarily the server will detect immediately.
Are you using https? If so, maybe we can test a patch on your server.

Rob Carlo

unread,
Dec 6, 2017, 8:03:59 PM12/6/17
to nginxpu...@googlegroups.com
Yes, using https. Can I buy an hour of your time?
Reply all
Reply to author
Forward
0 new messages