This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Gumball's profile picture

WebSocket implementation

Started by Gumball, 18 December 2016 - 05:59 AM
Gumball #1
Posted 18 December 2016 - 06:59 AM
This would make real-time internet communication possible with CC.
There's already an open-source library for WebSockets in Java, so it wouldn't be amazingly difficult.

This would make CC more fun and practical to use. What I think it should look like:


ws = os.loadAPI("websockets")
socket  = ws.connect("ws://PlaceThatProvidesAWebSocket")
emittedEvent,data = os.pullEvent("wsreceive")

socket.emit("eventName",{packet1 = "noice"})

This was suggested a couple years ago and didn't get much attention.

"data" would either be an array or string. You'd need to decode arrays that are sent first, but that shouldn't be difficult.
Edited on 18 December 2016 - 06:00 AM
SquidDev #2
Posted 18 December 2016 - 08:02 AM
CCTweaks provides a TCP socket system. The WebSocket spec doesn't look too hard to implement and it is built on top of TCP so you could have a go at implementing an API using that :)/>.
Gumball #3
Posted 18 December 2016 - 08:45 AM
I think it would be better without a mod, also I'm not very confident that I'd be able to implement that.
JustPingo #4
Posted 19 December 2016 - 01:58 AM
The websocket specification isn't enormous and pretty straight forward. I'm sure you could do it.
Xerxes #5
Posted 31 December 2016 - 11:40 PM
The websocket specification isn't enormous and pretty straight forward. I'm sure you could do it.
CCTweaks provides a TCP socket system. The WebSocket spec doesn't look too hard to implement and it is built on top of TCP so you could have a go at implementing an API using that :)/>.
The WebSocket spec is a royal pain in the ass to implement in Java, so I imagine it would be even more difficult to implement in Lua.