Websocket: Undefined error on sending a string

1,060 views
Skip to first unread message

Sal

unread,
Aug 5, 2014, 8:06:13 PM8/5/14
to elm-d...@googlegroups.com
I have an elm code defined here that simply sends a string over websocket: http://share-elm.com/sprout/53e1703ee4b07afa6f983cd8

Compiling and running it generates undefined error. This works fine if I write similar code in JS (just to confirm that the websocket is being opened, and command being sent). Are there any subtleties of websocket I am missing here? I could go back to using ports with JS but I want to avoid this, and keep the solution as simple as possible. 

I saw this discussion which seems to match my problem description: https://groups.google.com/forum/m/#!topic/elm-discuss/3xDhWg_CJYo/discussion

Can I do just selective patch of WebSocket library by downloading github patch? If not, is there another simple workaround short of rebuilding the entire compiler?

Ray Racine

unread,
Aug 5, 2014, 9:05:34 PM8/5/14
to elm-discuss
My initial attempts to use a the runtime websocket hit the initialization bug as well.  However, it appears a response filter deals with the problem.  Here are two POC  (non-standalone) examples from some Elm playing around that work for me.


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

Ray Racine

unread,
Aug 5, 2014, 9:13:39 PM8/5/14
to elm-discuss
Before I forget there is a second issue with the current native runtime WS support as well.  If you use Chrome as a client, you can watch the WS frames that go back and forth.   If you let it the browser sit idle, you can see the time out keepalive ping/pongs going back and forth.  However, if the connection is closed on the server side (Ctrl-C the server and restart it) your page is "dead".  You have to refresh the page.   i.e. The current client side WS support will not automatically reestablish the connection if there is an outbound message and the connection is in a closed state.

Sal

unread,
Aug 6, 2014, 9:34:11 AM8/6/14
to elm-d...@googlegroups.com
Ray, thanks for posting this. I saw that before but didn't understand what a "response filter workaround" is. If this can be applied to my simple example (I can test and validate myself), that would help understand it better. 

Sal

unread,
Aug 6, 2014, 9:51:56 AM8/6/14
to elm-d...@googlegroups.com
Hmm, figured it out. Swapping "plainText" with "asText" function (which takes generic type signature instead of string) solved the string bug.

Reply all
Reply to author
Forward
0 new messages