Playing with Portal and need some help

30 views
Skip to first unread message

Alexander Krause

unread,
Dec 25, 2013, 5:14:07 AM12/25/13
to portal_...@googlegroups.com
Hi there,

after googling for jsonp, jQuery and JSON-streaming I finally found Portal.

At the moment, thanks for the free time cos of holidays, I'm trying to stream some JSON data via a persistend web-socket or HTTP connection.

I got a server running which is able to provide a permanent HTTP connection and can stream some JSON data. Now I'm trying to get these data-chunks parsed with Portal.

My HTML-code somehow looks like this:

Viewing this page in the browser results in an additional GET request from Portal:
GET /rpc?when=open&transport=ws&heartbeat=false&lastEventId=0&id=df6354ae-b6f4-46a6-9584-e60db1744c7a&_=1387965636267 HTTP/1.1

How should I handle this request? At the moment I'm sending 
{"data": 0, "type": "message", "id": "df6354ae-b6f4-46a6-9584-e60db1744c7a", "reply": false}

But my browser calls GET multiple time which shouldn't be the case.

Also the transport is "ws", is this correct?

Is there a state-machine which moves from "open" to something else?


Thanks a lot for your hints!

Regards and some nice Holidays!

Donghwan Kim

unread,
Dec 25, 2013, 6:17:45 AM12/25/13
to portal_...@googlegroups.com
Hi Alexander,

I'm not sure what you try to do.

The default transport set is ["ws", "sse", "stream", "longpoll"] and WebSocket is available in your browser so that ws is selected as transport, but I guess that since your server doesn't support WebSocket, the socket provided by portal in browser fails to connect and reconnect repeatedly (multiple GET request). About the socket's state and event transition, see socket api doc from the web site.

Can you post your server-side code? otherwise, you can look at a test server used to develop portal.js.

Merry Christmas,

-- Donghwan


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

Alexander Krause

unread,
Dec 25, 2013, 8:34:50 AM12/25/13
to portal_...@googlegroups.com
You can find my current server in this tar:

It needs pycherry (cherrypy) and simplejson .

You can start it via:
python run.py

Opening http://127.0.0.1:8080 will give you a simple html file which uses Portal and reads /rpc .

It's most likely that I'm simple returning the wrong response in /rpc .

/rpc is handled by
 def RPC_handler(*args, **kwargs):

Which will end in an infinity loop which should simply send some data every second.

I'll check out the js-server example and will hopefully get an idea on how to fix my messaging ;-)

Regards,
Alex

Donghwan Kim

unread,
Dec 25, 2013, 9:45:54 AM12/25/13
to portal_...@googlegroups.com
Hi,

I fixed it but it's never correct answer since I have never done Python before so that I'm stuck on both cherrypy and Python. Anyway, try out!


Generally speaking, you need to choose transport set considering your app's runtime environment before writing server. It seems that cherrpy doesn't support WebSocket. If that is the case, you should exclude 'ws' from transport set.

-- Donghwan


--

Alexander Krause

unread,
Dec 25, 2013, 9:47:09 AM12/25/13
to portal_...@googlegroups.com
New tar:
https://dl.dropboxusercontent.com/u/86657762/pywebstory-0.0.1.tar.gz

I finally am on a good road after reading some more about WebSockets (http://tools.ietf.org/html/rfc6455) . With python you can use ws4py as I did in my cherrypy example.

Regards,
Alex

Am Mittwoch, 25. Dezember 2013 11:14:07 UTC+1 schrieb Alexander Krause:
Reply all
Reply to author
Forward
0 new messages