how to push msg to the specific browser from a TCP server

1 view
Skip to first unread message

Ping.Zheng

unread,
Oct 16, 2009, 10:57:15 AM10/16/09
to orbite...@googlegroups.com
Hi, all:
   I am testing http://localhost:8000/static/tests/freeform.html, I can send a data to my tcp server writen by twisted, and now I opened two brosers, I want to send a message from a browser to another brower, how can I do to push the msg to the specific browser.

--
with all kind regards

Jacob Rus

unread,
Oct 16, 2009, 1:44:36 PM10/16/09
to orbite...@googlegroups.com
Ping.Zheng wrote:
>    I am testing http://localhost:8000/static/tests/freeform.html, I can send
> a data to my tcp server writen by twisted, and now I opened two brosers, I
> want to send a message from a browser to another brower, how can I do to
> push the msg to the specific browser.

If each of your browser clients is connected to your server (you say
you are writing it in Twisted?), then all you need to do is make your
server pass the message along to the other client. To do this, you
probably want to keep a dictionary of connected clients somewhere
keyed by some identifier (perhaps username or similar), and develop a
protocol for addressing a specific one in the upstream messages. I
think Michael or Mario put up an example Twisted-based server which
sends framed messages between clients. Maybe someone will chime in
with a link to some code you could look at.

Hope that helps,
Jacob

BobDobbs

unread,
Oct 20, 2009, 1:25:47 PM10/20/09
to Orbited Discussion
It depends on your intentions. You can do it server side... and would
need to if you imagine many users and needing a directory between
them.

In the simplest case... you can just make two queues called "UserA"
and "UserB".

When User A opens the page... he subscribes to "UserA" and publishes
to "UserB". User B signs in and subscribes to "UserB" and publishes to
"UserA". If you have a control on you page that prints messages that
come across the user's subscribed channel, and a control that
publishes text from a text box on a button click to the publishing
channel... you have two people being able to chat with each other.

If there are many users... you would want a way for them to find each
other and know which queues to publish or subscribe on. Our system
uses the HTTP session id as the queue name so each browser instance
have a unique queue. If you were writing a chat program... much of the
server logic would be looking up other users and telling the browsers
what the queue names are for the various users in the system.

On Oct 16, 1:44 pm, Jacob Rus <jacobo...@gmail.com> wrote:
> Ping.Zheng wrote:
> >    I am testinghttp://localhost:8000/static/tests/freeform.html, I can send

BobDobbs

unread,
Oct 20, 2009, 1:32:30 PM10/20/09
to Orbited Discussion
Of course... by allowing people to know each other's queue names you
have a security risk (anyone could masquerade as anyone else). Jacob's
idea of having the server move the messages around the various queues
would allow the messages to move along without end user's being aware
of each other's queue names.

This would be important in a production system... but if you are just
playing around with Orbited for a personal project... it would be less
work to get it going by having the clients point at each other
directly.
Reply all
Reply to author
Forward
0 new messages