ANN: dmc_websockets - WebSocket module for Corona SDK

Yep, that helps.  Looks like everything needs to happen in the event loop on the client side.  Had to compile a new NetLogo extension on the Java side (scala).  Now I have an active port on the other end and I’m getting an ONOPEN event.  So the socket object seems to be “real” now.

Looks like your part is working as designed.  Great stuff!  Thanks.  Took a look at doing this myself about 6 months ago.  SOOOOO glad you did it for us.

Now for the undocumented handshaking with HubNet.

Thanks,

–Scot

Sending a JSON string and getting and ONERROR event.  Does the the event table contain any information besides type = “ONERROR”?  

The API docs on your site indicate this is due to a communication error.  Could this be a response from the server that the message does not make sense, or does this mean that the message never made it to the server?  Or is there a difference.

Thanks,

–Scot

there is a flag near the top of dmc_websockets.lua, called LOCAL_DEBUG. set to *true* will print out more info regarding the communication process to give a better idea when things go badly. tcp.lua and async_tcp.lua have the same.

usually there will be additional info in the event table on an error – properties ‘code’ and ‘reason’. are you seeing a traceback along with the error ?

i’m not sure when you grabbed your copy of the library. i know i have made some updates recently which output more information in certain error conditions. i have also published other updates within the past few days.

if a server doesn’t understand something it is supposed to close the connection cleanly with an error code/reason, not just drop it. of course, that’ll depend on the WS implementation of the server code. :slight_smile:

as far as onError, there isn’t a lot in the WS spec regarding when to throw that, i am thinking the only reasons to throw that would be an 1. internal error (like some Lua issue) or 2. the network connection was suddenly lost.

cheers,

dmc

ps, if you’re still having issues, i can take a look at your project if you are able to send it to me.

Thanks dmc,

Working with the developer of the NetLogo Extension now.  He may have some insight as well.  I appreciate the offer and I will send the code along as it becomes necessary.  

Thanks for your work, your thoughts and your help.

–Scot

Here’s what I get:

2014-08-16 20:21:57.660 Corona Simulator[5220:507] {“type”:“VersionMessage”,“fields”:{“version”:“NetLogo 5.0.4”}}

2014-08-16 20:21:57.661 Corona Simulator[5220:507] string

2014-08-16 20:21:57.661 Corona Simulator[5220:507] Received event: ONOPEN

2014-08-16 20:21:57.661 Corona Simulator[5220:507] 

dmc_websockets :: Unknown Error /Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/lua_objects.lua:440: attempt to index local ‘params’ (a string value)

2014-08-16 20:21:57.661 Corona Simulator[5220:507] stack traceback:

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:605: in function ‘_receiveFrame’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:960: in function ‘do_state_connected’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:931: in function ‘__curr_state_func’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/lua_states.lua:96: in function ‘gotoState’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:459: in function ‘_handleHttpRespose’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:921: in function ‘do_state_http_negotiation’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:896: in function ‘__curr_state_func’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/lua_states.lua:96: in function ‘gotoState’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:1119: in function ‘callback’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_sockets/async_tcp.lua:216: in function ‘receive’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:1126: in function </Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_websockets.lua:1081>

(tail call): ?

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_sockets/async_tcp.lua:400: in function ‘_doAfterReadAction’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_sockets/tcp.lua:383: in function ‘_readStatus’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_sockets.lua:435: in function ‘_checkConnections’

/Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_sockets.lua:461: in function </Users/scotsoutherland/Documents/Development/Websocket/dmc_corona/dmc_sockets.lua:458>

?: in function <?:221>

2014-08-16 20:21:57.662 Corona Simulator[5220:507] Received event: ONERROR

Still working on the other end to try to understand what is happening.  The version number I sent is important for NetLogo, so if there is a mismatch, NLogo might be dropping the connection.  Still struggling to see what is happening on the other end.  Almost entirely undocumented except in the code, which is pretty tedious work.

Seeing what’s happening on the server side now.  Websocket opens and immediately closes.  The version number is not the issue.  Connection is not persisting.

a couple of days ago i pushed a fix for that error “attempt to index local ‘params’ (a string value)” – not sure when you last updated from github.

also on github near the top of the ReadMe i have listed a couple of ways you can PM me. you can use one of them to send me a zip of your code. i’d like to get you to a point where the connection is stable (or find out why it’s not), then you can continue your work from there.

thanks, dmc

Downloaded and installed your latest version.  Looks like that did it.  

Encoded and sent a JSON string and received a JSON string back.  Server side Java websocket persisting now as well.

Important step forward.  Thanks for all your support.  Will keep you posted.

Output as follows:

2014-08-17 15:27:40.542 Corona Simulator[5220:507] 

Copyright © 2009-2014  C o r o n a   L a b s   I n c .

2014-08-17 15:27:40.542 Corona Simulator[5220:507] Version: 3.0.0

2014-08-17 15:27:40.543 Corona Simulator[5220:507] Build: 2014.2393

2014-08-17 15:27:40.556 Corona Simulator[5220:507] Platform: iPhone / x86_64 / 10.9 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-8.28.30 / 2014.2393

2014-08-17 15:27:40.628 Corona Simulator[5220:507] The file sandbox for this project is located at the following folder:

(/Users/scotsoutherland/Library/Application Support/Corona Simulator/Websocket-A7F64A150865B0DC24734D37DA1496ED)

2014-08-17 15:27:40.642 Corona Simulator[5220:507] Lua Patch::activating patch ‘table-pop’

2014-08-17 15:27:40.643 Corona Simulator[5220:507] Lua Patch::activating patch ‘string-format’

2014-08-17 15:27:40.649 Corona Simulator[5220:507] dmc_library:: Loading slower bitOp library

2014-08-17 15:27:40.753 Corona Simulator[5220:507] {“type”:“VersionMessage”,“fields”:{“version”:“NetLogo 5.0.4”}}

2014-08-17 15:27:40.754 Corona Simulator[5220:507] Received event: ONOPEN

2014-08-17 15:27:40.754 Corona Simulator[5220:507] BufferErrorFactory Read surpasses buffer size

2014-08-17 15:27:40.764 Corona Simulator[5220:507] Received event: ONMESSAGE

2014-08-17 15:27:40.765 Corona Simulator[5220:507] {“type”:“VersionMessage”,“fields”:{“version”:“NetLogo 5.0.4”}} text

2014-08-17 15:27:40.765 Corona Simulator[5220:507] BufferErrorFactory Read surpasses buffer size

Hello,

My app works with websockets on corona simulator, but I soon as I build it and launch it on my iPhone6, I have the following error messages :

Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Platform: iPhone / iPhone7,2 / 8.0.2 / Apple A8 GPU / OpenGL ES 2.0 Apple A8 GPU - 50.5.1 / 2014.2393 Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Lua Patch::activating patch 'table-pop' Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Lua Patch::activating patch 'string-format' Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Runtime error /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_websockets.lua:136: module 'dmc\_sockets' not found in archive: /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/ module 'dmc\_sockets' not found:resource (dmc\_sockets.lu) does not exist in archive no field package.preload['dmc\_sockets'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.lua' no file './dmc\_sockets.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.so'dmc\_sockets /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_sockets.lua:130: module 'dmc\_sockets.async\_tcp' not found in archive: /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/ module 'dmc\_sockets.async\_tcp' not found:resource (dmc\_sockets.async\_tcp.lu) does not exist in archive no field package.preload['dmc\_sockets.async\_tcp'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.async\_tcp.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.async\_tcp.lua' no file './dmc\_sockets.async\_tcp.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.async\_tcp.so' no file './dmc\_sockets.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.so'dmc\_sockets.async\_tcp /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_sockets/async\_tcp.lua:53: module 'plugin.openssl' not found in archive: /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/ module 'plugin.openssl' not found:resource (plugin.openssl.lu) does not exist in archive no field package.preload['plugin.openssl'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.openssl.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.openssl.lua' no file './plugin.openssl.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.openssl.so' no file './plugin.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.so'plugin.openssl /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona module 'dmc\_corona.plugin.openssl' not found:resource (dmc\_corona.plugin.openssl.lu) does not exist in archive no field package.preload['dmc\_corona.plugin.openssl'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.plugin.openssl.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.plugin.openssl.lua' no file './dmc\_corona.plugin.openssl.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.plugin.openssl.so' no file './dmc\_corona.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.so'dmc\_corona.plugin.openssl stack traceback: [C]: in function 'error' /Library/WebServer/Documents/myapp/mobile/dmc\_corona\_boot.lua:421: in function 'require' /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_websockets.lua:136: in main chunk [C]: in function 'require' ?: in function \<?:803\> (tail call): ? /Library/WebServer/Documents/myapp/mobile/main.lua:1: in main chunk

It occurs with the one and only require line :

local WebSockets = require ‘dmc_corona.dmc_websockets’

Is this a bug, or is there anything I may have done wrong ? (it works very well on simulator).

Thanks,

Olivier

hi Olivier, thanks for putting this on github. i’m just going to continue this over there, but:

one thing i notice from the traceback is that the open SSL library isn’t getting loaded. that comes from Corona Labs itself and is imported using the build.settings file. looking at the ‘echo’ example, it looks like the import for the SSL lib is missing from the build.settings file. :frowning: i will update the example.

for now, you can look at the the settings file for the ‘pusher’ example and use that instead.

Thanks for your answer.

Unfortunately, openssl is a plugin only available for PRO subscribers. Is there a way not to use this plugin in websockets ?

Thanks.

Hey dmc,

Just posting to verify that I was successful in reverse engineering the NetLogo Hubnet Protocol through the websocket.  We can now connect with NetLogo models via the Hubnet-Web extension.

Thanks for your help and your great work.

Best,

–Scot

hey Scot,

that’s fantastic news ! i’m glad to hear that your project is going well. thanks for the kudos, too. :slight_smile:

cheers, dmc

Hello,

My app works with websockets on corona simulator, but I soon as I build it and launch it on my iPhone6, I have the following error messages :

Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Platform: iPhone / iPhone7,2 / 8.0.2 / Apple A8 GPU / OpenGL ES 2.0 Apple A8 GPU - 50.5.1 / 2014.2393 Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Lua Patch::activating patch 'table-pop' Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Lua Patch::activating patch 'string-format' Oct 2 16:16:09 iPhone-de-olivier myapp[2241] \<Warning\>: Runtime error /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_websockets.lua:136: module 'dmc\_sockets' not found in archive: /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/ module 'dmc\_sockets' not found:resource (dmc\_sockets.lu) does not exist in archive no field package.preload['dmc\_sockets'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.lua' no file './dmc\_sockets.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.so'dmc\_sockets /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_sockets.lua:130: module 'dmc\_sockets.async\_tcp' not found in archive: /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/ module 'dmc\_sockets.async\_tcp' not found:resource (dmc\_sockets.async\_tcp.lu) does not exist in archive no field package.preload['dmc\_sockets.async\_tcp'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.async\_tcp.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.async\_tcp.lua' no file './dmc\_sockets.async\_tcp.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.async\_tcp.so' no file './dmc\_sockets.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_sockets.so'dmc\_sockets.async\_tcp /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_sockets/async\_tcp.lua:53: module 'plugin.openssl' not found in archive: /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/ module 'plugin.openssl' not found:resource (plugin.openssl.lu) does not exist in archive no field package.preload['plugin.openssl'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.openssl.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.openssl.lua' no file './plugin.openssl.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.openssl.so' no file './plugin.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/plugin.so'plugin.openssl /private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona module 'dmc\_corona.plugin.openssl' not found:resource (dmc\_corona.plugin.openssl.lu) does not exist in archive no field package.preload['dmc\_corona.plugin.openssl'] no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.plugin.openssl.lua' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.plugin.openssl.lua' no file './dmc\_corona.plugin.openssl.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.plugin.openssl.so' no file './dmc\_corona.so' no file '/private/var/mobile/Containers/Bundle/Application/AC5F1AFF-16AE-4CA2-BFF8-176AFDD3C516/myapp.app/dmc\_corona.so'dmc\_corona.plugin.openssl stack traceback: [C]: in function 'error' /Library/WebServer/Documents/myapp/mobile/dmc\_corona\_boot.lua:421: in function 'require' /Library/WebServer/Documents/myapp/mobile/dmc\_corona/dmc\_websockets.lua:136: in main chunk [C]: in function 'require' ?: in function \<?:803\> (tail call): ? /Library/WebServer/Documents/myapp/mobile/main.lua:1: in main chunk

It occurs with the one and only require line :

local WebSockets = require ‘dmc_corona.dmc_websockets’

Is this a bug, or is there anything I may have done wrong ? (it works very well on simulator).

Thanks,

Olivier

hi Olivier, thanks for putting this on github. i’m just going to continue this over there, but:

one thing i notice from the traceback is that the open SSL library isn’t getting loaded. that comes from Corona Labs itself and is imported using the build.settings file. looking at the ‘echo’ example, it looks like the import for the SSL lib is missing from the build.settings file. :frowning: i will update the example.

for now, you can look at the the settings file for the ‘pusher’ example and use that instead.

Thanks for your answer.

Unfortunately, openssl is a plugin only available for PRO subscribers. Is there a way not to use this plugin in websockets ?

Thanks.

the library has been updated to not autoload the SSL plugin at the start, only when accessing a secure URL.

the library has been updated to not autoload the SSL plugin at the start, only when accessing a secure URL.

Note I have this working with TSL now, fix is documented here:

1 Like