Comments (19)
Is this fixed ?
from gevent-socketio.
I will verify tonight
from gevent-socketio.
I've found that BaseNamespace.recv_connect() doesn't get called for the global namespace, but does get called on specific endpoints. Conversely, I also noticed that the "connect" event never fires on the client if an endpoint name is used, but does fire if no endpoint name is specified.
from gevent-socketio.
Is it any progress on the issue?
from gevent-socketio.
Tested master branch: both recv_connect and recv_disconnect doesn't work for me.
I use code like the following and see only "called" message, but no "connected" or "disconnected":
class MainNamespace(namespace.BaseNamespace):
def on_my_init(self, data):
print "called"
def recv_connect(self):
print "connected"
def recv_disconnect(self):
print "disconnected"
And attaching using this namespace in request handler this way (stolen from cross_origin example, request is the Werkzeug's Request object):
socketio_manage(request.environ, {'': MainNamespace}, request=request)
And, yes. I'm connecting to server, calling my_init method, waiting a bit and then closing browser tab.
from gevent-socketio.
Yeah, there is ambiguity here. The "recv_connect" call is received only when we receive a CONNECT packet.. On the "global namespace", the empty string that is, no such packet is sent.. because the opening of the connection is itself the "connect" event. Instead, on the global namespace, we should implement the "connect(self)" method.
Same thing goes for disconnect. There is a disconnect packet that can be sent to close an endpoint (or namespace), but it is not sent for the global namespace.
So there might be a solution: we could remove recv_connect(self), and recv_disconnect(self), and call in both cases (even though they are different events) "connect(self, type)" and "disconnect(self, type)".. where 'type' would be what triggered the event. I know it's not very nice.. or maybe we should just update the documentation ? Or maybe we should discourage the usage of the global namespace, as it is there mostly for backwards compatibility.
What do you think ?
from gevent-socketio.
30.05.2012, 22:35, "Alexandre Bourget" [email protected]:
Yeah, there is ambiguity here. The "recv_connect" call is received only when we receive a CONNECT packet.. On the "global namespace", the empty string that is, no such packet is sent.. because the opening of the connection is itself the "connect" event. Instead, on the global namespace, we should implement the "connect(self)" method.
Same thing goes for disconnect. There is a disconnect packet that can be sent to close an endpoint (or namespace), but it is not sent for the global namespace.
Thanks, I understand the problem now.
So there might be a solution: we could remove recv_connect(self), and recv_disconnect(self), and call in both cases (even though they are different events) "connect(self, type)" and "disconnect(self, type)".. where 'type' would be what triggered the event. I know it's not very nice.. or maybe we should just update the documentation ? Or maybe we should discourage the usage of the global namespace, as it is there mostly for backwards compatibility.
What do you think ?
I wonder how does it work with node.js implementation (it actually works!). I suppose the best way is to choose the same or similar solution.
Handlers "connect(self, type)" and "disconnect(self, type)" looks like a spike for me, because it negates all advantages of RPC.
Also, It will be nice to mention in documentation that recv_* functions doesn't work for global namespace.
Reply to this email directly or view it on GitHub:
#9 (comment)
Best regards,
Vladimir Protasov.
from gevent-socketio.
Okay, I've got deeper into docs and now I see that global namespace is supported only in 0.6.
So, I think it will be enough to mention in documentation for recv_* functions that it doesn't supported for global namespace.
Best regards,
Vladimir Protasov.
from gevent-socketio.
It seems that the Python code and JS code are at odds with one another. For example, I have some JS code as follows:
var global_socket = io.connect();
var socket = io.connect("/console");
// "connecting" event fires for specific namespaces
socket.on("connecting", function (transport_type) {
$("#state").text("connecting to " + transport_type + "...");
});
// Note global_socket, as "connect" event does not fire for specific namespaces
global_socket.on("connect", function () {
$("#state").text("connected");
});
But then on the Python side of things:
class ConsoleNamespace(BaseNamespace):
def recv_connect(self):
# Spawn custom method upon Socket.IO client-namespace connect
self.spawn(self.listener)
def listener(self):
while True:
# Do custom background stuff
gevent.sleep()
The recv_connect() is called upon 'socket = io.connect("/console")' (routed to the ConsoleNamespace by socketio_manage()), which spawns my custom class method (which lurks in the background, monitoring a TCP socket and occasionally emit()'ing packets to the Socket.IO client connection).
However, if I didn't have the explicit no-namespace "global_socket = io.connect()" in the JS, then I'm not able to determine on the client when it has successfully connected.
I'm open to any suggestions on how to more gracefully handle this.
from gevent-socketio.
We need to handle this how the node.js implementation does. I assume since their client is only firing the packet on named namespaces, their server probably doesn't do anything different than we are currently doing.
We should make a node.js sample app that tests this.
from gevent-socketio.
Whilst searching for answers about this, I stumbled across this page http://sideeffect.kr:8005/
If you scroll down a little way to the namespace example, it looks like node.js will send a "connect" event when using a namespace... which would seem to indicate that gevent-socketio needs to do that also.
from gevent-socketio.
Oh, so when we create the namespace, we should ourselves send a 'connect'
packet to the browser ?
On Tue, Jun 26, 2012 at 5:16 PM, Daniel Swarbrick <
[email protected]
wrote:
Whilst searching for answers about this, I stumbled across this page
http://sideeffect.kr:8005/
If you scroll down a little way to the namespace example, it looks like
node.js will send a "connect" event when using a namespace... which would
seem to indicate that gevent-socketio needs to do that also.
Reply to this email directly or view it on GitHub:
#9 (comment)
from gevent-socketio.
fixed on 0df3e5c
from gevent-socketio.
Sorry, I think this is still not working correctly. The "connect" event still does not fire on the client when connecting to a namespaced endpoint. For example:
socket = io.connect("/foo");
// This never fires
socket.on("connect", function () {
alert("connected");
});
I don't want to fire some user-connect event, when somebody joins a chat room. I want to know when the socket.io endpoint has successfully connected. This (I thought) is the purpose of the "connect" event firing.
I can get a "connect" event to fire if I use a non-namespaced endpoint.
from gevent-socketio.
Also, I noticed while testing, that if I add recv_disconnect() Python method to my namespace, it is being called repeatedly if the page has been refreshed... I'm not sure if this expected behaviour or not.
from gevent-socketio.
If you define a recv_disconnect() you need to call self.disconnect() yourself. (Thinking about ways to make that cleaner), that is why you are getting the repeat.
I'll fix the connect so that it fires properly.
from gevent-socketio.
Fixed in e039720
from gevent-socketio.
@sontek Thanks, that finally fixed it :)
from gevent-socketio.
@dswarbrick that is nice.. our kludge goes away as well
from gevent-socketio.
Related Issues (20)
- How to broadcast data to a room (of socket io) when the server receives data from somewhere else (not using socket io)
- headers use integer for Access-Control-Max-Age HOT 1
- GeventSocketIOWorker fails to boot when used with gunicorn and ssl flags
- WebSocket is closed before the connection is established. HOT 1
- gevent UnicodeError HOT 3
- django.utils.importlib is removed in Django 1.9 HOT 1
- Merge working tests MR and ask people to rebase
- About renaming the "socketio" library name
- BaseNamespace.session
- SSL Error
- Django 1.10 Support
- django example won't install
- WebSocketError: Received "Socket is dead".
- My chat room sometimes the user sends the text all become?????
- how to run socket.io chat app from two different ports
- Tag 668d11edbd62052cde1583be1e1d0512c930f16d as 0.3.6?
- Release 0.3.7 with post-0.3.6 fixes? HOT 1
- Is it possible to use gevent-socketio as a socket.io client? HOT 1
- KeyError: 'socketio' in socketio_manager
- Version compatability issue on Executing Tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gevent-socketio.