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

ComputerCraft RCon - Remote Shell/Monitor - Rednet

Started by DreadKyller, 09 August 2013 - 11:47 AM
DreadKyller #1
Posted 09 August 2013 - 01:47 PM
Title: ComputerCraft RCon - Remote Shell/Monitor - Rednet

I'm relitivly new to ComputerCraft, but not to lua and other scripting languages. I tried for a few days now to find a solution myself but being inexperienced with the ComputerCraft API I failed to find a solution. From what I've read on the forum, this is a faily advanced task that I'm asking, and I'm not asking for the code because I feel that would be too tedious for people to need to reply with. I'm looking for the concept of how to get a Remote Shell/Monitor system setup.

Essentially in it's simplest form I would like to be able to pass the instance of shell and/or monitor through rednet and use those variables on the connecting computer to control the remote computer, however I know that that is not possible to do normally. I tried to use textutils.serialize and unserialize to pass the instances as a string, however as you know textutils.serialize() can not serialize functions, and both monitor and shell are essentially a collection of functions in a table. I wrote my own serializer using string.dump() and loadstring() and I was able to parse the objects again, however in the process of reconstructing the data the new instance of shell was just that, a new instance, not linked, different address. To the most extreme I could think there might be a way to implement assembly code to use array-of-byte scans and mov opcodes to change the address of the new instance, but that would just be useless waste of time to even think of attempting.

I know RCon is feasible with a server/client program server sends user input, client recieves user input and processes it, and then sends the results back to server. However that would not work well in my case. I would like to be able to remotely connect to multiple of my computers and have full remote access to them, example, if I run the program "paint" I want to be able to paint on the remote computer and see the painting on the connected computer, which I guess it might be possible to literally gather the screen information and send it over, granted the fact that a program is running and I can't run other code alongwide that program (unless ComputerCraft has some form of Multithreading that I don't know of). If I type in lua on the connected computer, I want the lua prompt to show up and allow me to use the lua prompt, which a program cannot be running on the computer at the same time, so I can't just be using a client program to interpret the input and send the output. There are only two ways to achieve this from what I'm seeing:

1) Somehow send the connecting computer a string which is the serialized version of a pointer pointing to the remote computer's specific instance of shell/monitor

2) Find a way to multithread the operations so that the client program can run in the background controlling the computer while the computer is free to perform any operation it normally would with no programs running.

Neither of those methods I've had any luck with and was hoping someone could point me in the right direction (If this is possible at all).
Bubba #2
Posted 09 August 2013 - 01:48 PM
Split into new topic.
DreadKyller #3
Posted 09 August 2013 - 01:50 PM
That was extremely fast. Less than a minute. Thanks.
Bubba #4
Posted 09 August 2013 - 01:57 PM
The first option is not feasible - ComputerCraft does not allow users to manipulate actual memory addresses, and even if it did that would be a rather hacky/poor solution to this problem. Not to mention the fact that ComputerCraft runs Lua on a Java VM, which has no pointers. Technically you could probably manipulate remote computers by editing Java code, but there is no reason to do so.

The second option is quite feasible. In order to do this you can go one of two routes (or, I suppose, you could mix the two but it would really serve no purpose).
1) Use the parallel API in order to achieve multi-tasking.
2) If you're like me and enjoy a challenge, use coroutines to achieve multi-tasking

Either one of these options would you allow to run multiple functions at the "same" time (not actually multi-threading, but it's close enough and suits pretty much all ComputerCraft purposes).
Bubba #5
Posted 09 August 2013 - 02:01 PM
Oh and here's proof that this can be done :)/>
DreadKyller #6
Posted 09 August 2013 - 02:13 PM
Oh and here's proof that this can be done :)/>

… I looked for hours using google, on this forum, and many other places seeing if someone had created something like this, didn't find anything, and then started working on my own… How did you find that post, because I almost literally looked everywhere for something like that.
Lyqyd #7
Posted 09 August 2013 - 02:38 PM
A search like "site:computercraft.info remote shell" (for which nsh is the fourth result) is usually a pretty effective way to look for things.

Also, nsh is fairly well-known around here, so he probably went through my profile to find topics I've created to get to it. ;)/>
DreadKyller #8
Posted 09 August 2013 - 10:45 PM
Well it's working perfectly, I edited it to allow for multiple connections. essentially I wanted this system to simplify my server loading syncronization, my automated machines all have a program that returns to starting location and then launches the automation program, I made the startup program execute shell.run("nsh host"), and then my main computer up startup after delay, connects to the hosts and executes the initalization program. Everything's running off a config so I can save a file chooseing which automated processes startup by default. Thank you for this. @Lyqyd never knew google could search only on specific sites, but I did search "remote shell" and remote terminal" in te search bar in this site and only found people asking for help, and then the TRoR, I didn't see nsh on that list.
Lyqyd #9
Posted 10 August 2013 - 04:40 PM
Oh, nsh already allowed multiple connections per host (though only one at a time from any given computer). I'm glad you've found it useful so far though! It's always nice to hear about people getting good use out of it.