On Sep 28, 2013, at 7:24 PM, Clavier <bachcalv...@gmail.com> wrote:

> I understand the limitation in a web browser.  Anyway there are a lot of chat 
> applications running in web browsers.  How can a chat application be built in 
> Pyjs if incomming socket communication is not allowed?

There are lots of options.

The oldest (and still most reliable cross-browser) technique is something 
called "long polling" 
<https://en.wikipedia.org/wiki/Push_technology#Long_polling>; basically, you 
can issue a request with PyJS's built in HTTPRequest class, and have the server 
leave that request un-answered until it has something to say to the client.  If 
the client just does this forever in a loop, then the server can answer at its 
leisure.

This can be written with no new JavaScript code, not even any small JS(...) 
wrappers, since PyJS ships with an existing HTTP request wrapper.

> I took a look at chat applications in web browsers supporting socket 
> communication. Socket.IO or WebSocket were used and they were Javascript. 
> Tornado is python library for asynchronous call supporting callback, but it 
> uses javascript for Socket.IO.

My suggestion is to build a client and a server that can communicate using 
multiple techniques.  I would start with long polling rather than Socket.IO or 
Tornado for several reasons:

You can do this in PyJS today, just fine, with no new JavaScript code.
If you want this to work reliably in multiple browsers, you will have to build 
a fallback just fine.
Because protocols for websockets and browser APIs for exposing two-way 
communication are evolving, you really need to build an abstraction within your 
PyJS framework for encapsulating the message-channel part of your protocol.  
You don't want to expose either WebSocket _or_ Long Polling as your API, but 
rather, give applications a generic API of your own design and provide multiple 
implementations so that you can choose the best one available in a given 
browser.  Long polling is the lowest common denominator that works everywhere, 
so it's the best one to start with.

>     http://socket.io/
>     https://github.com/facebook/tornado/blob/master/demos/chat/static/chat.js
> 
> I think that socket communication had been limited in a web browser in the 
> past, but not anymore in recent days.

Socket communication is still quite limited.  "WebSockets" are not "sockets in 
a web browser", but rather a new protocol, 
<http://www.rfc-editor.org/rfc/rfc6455.txt>.  If you want to talk to a server 
speaking an existing protocol, you still need a server-side proxy that will 
change WebSocket data into actual socket communication for you.

> I believe that Pyjs should support socket library for a web browser. 
> Otherwise, chat applications and other interactive web applications cannot be 
> built.

I agree.  It would be great if someone would make such a thing!

> I will try to integrate Socket.IO and Pyjs (or Tornado and Pyjs). Anyway It 
> is not pure python because they use javascript for socket communication. I 
> like the Pyjs philosophy using everything in python.  I appreciate any 
> comment about building a chat application in Pyjs framework. 

Although for your purposes it will be very similar to Tornado, I'd love it if 
you would also consider integrating Twisted <https://twistedmatrix.com/>.

> Thanks again

Good luck with your work, and please keep sending messages to this list!  (And 
contributing pull requests to PyJS itself...)

-glyph

-- 

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

Reply via email to