문제

I'm trying to learn new technology called Web Sockets. I've got the setup (pywebsocket as Apache2 module) working and I'm playing with examples. http://code.google.com/p/websocket-sample/wiki/samples?ts=1262888726&updated=samples

One thing is bothering me - all the examples use shared file to monitor changes in message counter, counter of users.

So basically when I connect to ws://localhost/chat with 2 browsers 2 instances of chat_wsh.py (websock handlers) will be running. Right? And they all will be accessing file/database for count.

It might be a silly question, but I'm not a network guru - is it possible to broadcast a message to all connections from one handler.

For example: User from chat sends a message - message through websocket gets to websocket handler which in turn broadcasts info that new message is received to all other chat instances, eliminating thus the need for each instance to constantly check on one shared file/database.

I hope I make sense :)

도움이 되었습니까?

해결책

I think you are trying to describe UDP Multicast.

See this link for more info Multicast

Unfortunately Websockets work over TCP which are as you have discovered for one-to-one connections.

You can look into somthing like memcached http://memcached.org/ to make it "low overhead" to keep a shared state of the chatroom

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top