LiveCode and WebSockets
Mark Wilcox
m_p_wilcox at yahoo.co.uk
Tue Jul 9 05:33:31 EDT 2013
>> Would you care to discuss the difference between websockets and the socketswe work with in livecode or point me to some basic information on the
websocket implementation you think we could implement in pure livecode?
What things would keep it from working very efficiently?
I see you already have some good references. Proper websockets implement a protocol on top of standard TCP socket connections on port 80. I think you could write or port an implementation of this protocol directly using the sockets available in desktop LiveCode.
For socket.io there are also other transports available (i.e. web sockets are emulated over some other transport). I think it might be possible to implement the XHR-polling transport in LiveCode, using load URL for the GET request (with the header set to keep the connection alive - it doesn't return anything until the server wants to send you something) and doing standard HTTP posts. What I don't know is whether LiveCode can actually do a POST request while you still have an async load operation running, or whether it will keep the HTTP connection alive as required by XHR-polling (a.k.a. long polling) rather than just timing out??
As for efficiency, LiveCode has pretty good performance because the language is very high level, so each line of code typically does quite a lot in native code in the engine underneath. Implementing a protocol is quite a low-level thing to do in such a high-level language, parsing/formatting all the messages in LiveCode directly is probably quite computationally expensive vs just putting/getting the content of those messages into/from a "websocket object" that handles the formatting/parsing for you in native code.
Also, as Pierre said, you could kludge this through the browser too, using the socket.io client directly. That's going to be much, much less efficient though.
Mark
More information about the use-livecode
mailing list