Socket in Codea-Runtime?

Hi. In the code for the runtime, I’ve seen these lines:


    {"mime", luaopen_mime_core},    
    {"socket", luaopen_socket_core},

Is it possible to enable sockets in the runtime, or is that code obsolete? It would be nice to dry code on Codea and then be able to use sockets if needed in the runtime. Or has anyone tried http comet requests to be able to have network communication without polling?

Sockets were rejected by apple - for networking, use http.get (now http.request).

They didn’t fit all that well with the codea programming loop anyway, fwiw - it’s hard to deal with blocking calls in an evented architecture. The http.get stuff, with it’s callbacks, is much easier to use for most purposes.

@tnlogy it’s possible to add the sockets library to the runtime. It just used LuaSockets. You may have to find and add the library yourself, and load the necessary Lua files before your project runs.

@Bortels sockets weren’t rejected by Apple — we were afraid they might do that, but we never submitted it to them. Instead we decided against their inclusion because we wanted a better API, something quicker to use that didn’t require the code overhead of sockets.

(I have a pretty strong dislike of the C sockets API design, and LuaSockets is heavily based on that. I feel it can, and should, be done better.)

Thanks for the replies. I agree with the dislike of the lua sockets api, it would be nicer with a more event based api.

But, maybe a good way to get around Apple restrictions would be to have some extensions in the runtime, so that Codea can be used for fast prototyping, and then be able to use a runtime that can do even more than Apple allows for an development environment on the iPad. Are you open to contributions to the Codea runtime, other than only bug fixes?

@tnlogy we are open to contributions. We will still have a lot of discussion before any API additions, but contributions are very welcome.

Would be real good to have some sort of sockets, I feel a bit limited right now.

Nice to know. But currently http.get works fine using it with to parse JSON-data.

Oh! I thought it was an apple thing.

Then I’d like to request udp.send() and udp.listen(), please :slight_smile: - udp.send just sending a udp packet, and udp.listen registering a port and a callback function. Insanely easy and good for network gaming.

Also, bonjour/zeroconf, please.

while we are at it: zeromq please?

Hello all,

Can someone send us a modified version of codea runtime with socket added/activated ?
or how to do that ?


Raw sockets in codea aren’t as exciting as you might think - the runtime architecture is all wrong, in that if/when you block on a socket - everything stops. That’s no good. I called for sockets until everyone got sicks of me, they added them to a beta, and I tried to make it work, and truth be told, the async stuff that’s there now is more useful.

You can do http.get now (or somesuch - might be http.request?) and get to websites, and it supports https as well as POST and so on, so that’s 90% of what you’d want nowdays. Peer to peer would be nice, but I think the thought has been that we should use the ios gaming library support for all of that (which, yes, isn’t there yet… fingers crossed).

Ouch, i have to use OSC to etablish connection to Ableton Live.
OSC is a UDP protocol.

Any ultimate idea ?


Nothing good - not without TLL putting in an async UDP listener like they did for the http return (which would be pretty cool for local gaming, I must say), or porting one of the OSC modules for lua. Even if you had raw sockets, in the default paradigm you block to receive - you’d have to fork (or maybe you can event poll? I don’t even know). Point is - ugly.

If I was doing this, now, today - I’d probably write a cgi to live on the same box that you’re running Ableton on, that could listen to commands from Codea, then send OSC to Ableton. But - I have no idea how I’d implement return events.

I… I hate to even say this. Codea is all things to all men - but it’s run loop is the exact opposite of what you’re looking for. Given that - take a look at pythonista. It’s python, which is annoying, but it can run old-school sockets. Will it do multiple threads, so you can block on read and still handle input? Dunno. But it’s probably worth looking at.

How about Firebase? they have an iOs SDK and they provide an amazing stack for real-time push AND storage.