socket.io confusion

35 views
Skip to first unread message

Łukasz Grabowski

unread,
Aug 5, 2017, 7:23:22 AM8/5/17
to bry...@googlegroups.com
Hi,

I'm trying to replace javascript with brython in my app completely.
Pretty much the only thing which is left is socket.io communication. So
on server side I'm using flask_socketio module. On the client side the
relevant javascript code which establishes connection is:

var socket=io.connect('http//localhost:7000,{'path':'{{/user0/my_socket.io}}'});

where io is provided by socket.io.min.js. Then I can emit events such
as:
socket.emit('save_file_event', {content: txt, filename: fname})

I thought I could use browser.websocket, but so far I didn't succeed
to establish connection. Any help would be appreciated!

Best,
Lukasz

Łukasz Grabowski

unread,
Aug 5, 2017, 9:01:29 AM8/5/17
to bry...@googlegroups.com
> So on server side I'm using flask_socketio module. On the client side
> the relevant javascript code which establishes connection is:

I managed to get it to work, by RTFM.

I have
<script type="text/javascript">
var socket = io.connect('http://localhost:7000',{'path':'/user0/screw_socket.io' });
</script>

and then within brython part I can do for example:
window.socket.emit('savefile', {'content': whatever })

However my "gotcha" moment was that I initially had the "var socket = "
part in a jquery $(document).ready() call, and then it doesn't work
(this is mentioned in brython docs as well...)

Perhaps brython could come with some sort of
"brython_goodies.js", where a couple of popular js libraries
bindings would be provided (I'm thinking of ion.sound and socket.io and
maybe something for key bindings as currently what's provided by
brython is not super convenient...) (it's a "spur of the moment"
suggestion, I didn't really think it through :-) )

Best,
Lukasz

Kiko

unread,
Aug 5, 2017, 12:16:22 PM8/5/17
to bry...@googlegroups.com
Hi Lukasz,

It would be great if you can document how is it going your trip from js to Brython:

* Gotchas
* Motivation for the port
* General performance (as a feeling, not necessarilly measurements)
* Other comments

I know that this can take you some time but if you can find the time it is a way to help and encourage others.

Thanks in advance.

Kind regards.



Best,
Lukasz

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/20170805140123.4a4f24cd%40brutus.lancaster.ac.uk.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages