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

ccnet (Formerly endernet http edition)

Started by sploders101, 20 June 2017 - 12:07 AM
sploders101 #1
Posted 20 June 2017 - 02:07 AM
Welcome to ccnet!


This is a spinoff of the endernet mod, written fully in lua and node (for the server)!
With this utility, you can connect to a communication server to facilitate messages from anywhere to anywhere. Clients can be written for in-game computers as well as real computers (JS api to come), and because it uses an external HTTP server, there is infinite range, no modem required, and the computers don't even have to be on the same server!

Uses:
  • Long-distance communication without repeaters
  • Cross-dimensional communication
  • Weather-independent communication
  • Communication with programs and web apps
  • Could be especially useful for ssh by connecting computers within ccemu to in-game computers on servers
Endernet HTTP is surprisingly fast, utilizing express and node js methods to keep connections alive by disabling timeouts; no polling required! HTTP events are handled through endernet.middle(), which is meant to replace os.pullEvent(), helping to keep connections alive no matter what's going on.

How it works:
  1. In-game computers connect to http server
  2. http server stores response methods for use later
  3. Client connects to server and sends message to a topic
  4. Server looks topic up in it's object and sends message to each client in the array
  5. Server returns number of clients that were connected (theoretical; disconnected clients are still in the array)
How do I use it?
  • –To use in your program, the following lines must be added.
  • –os.loadAPI("endernet") –os.pullEvent = endernet.middle –os.pullEventRaw = endernet.middleRaw – –This API exposes the following methods (NOTE: all topics MUST begin with "/", otherwise they will be dropped with 404 error code) –send(string topic, string message) –Sends a message to the specified topic –Returns maximum number of possibly connected clients (Not all that useful, but can be informative) –subscribe(string topic) –Subscribes to a topic in order to receive messages from it –Returns nil –assert(string topic) –Asserts a topic, renewing a request in case its connection is dropped –unsubscribe(string topic) –Unsubscribes from a topic –Returns nil –receive() –Receives message from any of the subscribed topics –Returns topic, message –middle(event) –Meant to replace os.pullEvent, and handles http events in order to keep them alive –middleRaw(event) –Same as above, for os.pullEventRaw
Downloads:
Edited on 24 June 2017 - 04:19 PM
sploders101 #2
Posted 24 June 2017 - 03:42 AM
Updated original post with a demo server, as well as updating the pastebin. Use of the demo server is not recommended for important tasks, but may be used if you do not want to create your own.