Re: [codenameone-discussions] using socket.io in BrowserComponent

40 views
Skip to first unread message

Steve Hannah

unread,
Mar 21, 2018, 3:35:48 PM3/21/18
to codenameone...@googlegroups.com
I haven't used socket.io before.  But here is the strategy I would use for testing:

1. First try to get it working with a visible browser component.  Having it invisible may present some extra obstacles.
2. Make sure you are using the polling option of socket.io because the BrowserComponent in the simulator doesn't support Websockets.  (This is not to be confused with the websockets cn1lib - as CN1 does support websockets, just not inside the BrowserComponent).
3. Create as small a test case as possible to demonstrate your issue, and share the bits of code where you're getting stuck - and I can try to help.

If you're using the BrowserComponent just for a socket.io client, I would suggest instead to try to port the Android socket.io client to Codename One

Most of this would should be pretty straight forward.  You'd just need to change the WebSocket code to use cn1-websockets instead of the Android websocket API.

Steve

I am trying to use the socket.io javascript lib in a BrowserComponent (that is not displayed).
When I send a message (=emit) to the server, everything is working fine. The server correctly receve the emited packet. However, when the server try to answer, it fails with a "connection timeout" error (and the packet is never received by the codename one app, that I run in the simulator). The connection between the cn1 app and the server is still active though as, if I kill the simulator (that runs the cn1 app), the server is correctly able to detect that the connection has just been closed. 
Any idea of what may be the reason of this "connection timeout" error (the server is not at cause here as it works just well with a react-native app that I am trying to port to cn1)? Anyone already succeed using socket.io with the BrowserComponent?

tomber...@gmail.com

unread,
Mar 22, 2018, 2:03:35 PM3/22/18
to CodenameOne Discussions
First of all. I really do not appreciate to have my email publically exposed like that (I am already spamed enaugh). So please edit your answer to delete it.

In what concerns socket.io inside the BrowserComponent, I finally got it working with no issue, even inside the Simulator (websockets works just fine in it). That is why I deleted my post (the 'connection timeout' message I had on my server was actually unrelated to socket.io).
As for porting the android socket.io library to codenameone, this is clearly not something I would call 'straight forward'. It could have been if cn1 supported the complete java API but, as not the case, a port to cn1 would requiere many changes into the java socket.io lib and its dependencies. And socket.io do not only relly on websockets, it also use some AJAX or JSONP protocol for the handshake.
So I am still considering whether it is worth the hastle porting the java socket.io lib to cn1 or make a cn1 native wrapper around this android lib and the socket.io swift lib for iOS rather than just stick with using the javascript version into the BrowserComponent...


Steve Hannah

unread,
Mar 22, 2018, 2:18:31 PM3/22/18
to codenameone...@googlegroups.com

On Thu, Mar 22, 2018 at 11:03 AM, <tomber...@gmail.com> wrote:
First of all. I really do not appreciate to have my email publically exposed like that (I am already spamed enaugh). So please edit your answer to delete it.

I have no idea what you're talking about.  You sent an email to a public mailing list.  I replied to this public post on this public mailing list by pressing "Reply".  I won't be editing or deleting any answers.

Steve
Reply all
Reply to author
Forward
0 new messages