Skip to content

Implement remote commands#2629

Open
kgmt0 wants to merge 37 commits intoNetLogo:wip-7.1from
kgmt0:remote-commands
Open

Implement remote commands#2629
kgmt0 wants to merge 37 commits intoNetLogo:wip-7.1from
kgmt0:remote-commands

Conversation

@kgmt0
Copy link
Copy Markdown
Contributor

@kgmt0 kgmt0 commented Feb 8, 2026

When enabled, this creates a Unix socket (or a named pipe on Windows) that listens to commands. An external editor can use this socket to send commands for NetLogo to run in the form of JSON objects that look like this: {"type": "nl-run-code", "code": "show 123"}.

This still needs to be tested on Windows and OSX. I've only tested it on Linux. On Linux (and probably OSX too), an easy way to test this is to use OpenBSD Netcat (GNU Netcat doesn't support Unix sockets). You can open a connection like this nc -U /path/to/socket/netlogo-1234 and enter the JSON Object you wan to send. On Linux and OSX, the socket will be put in XDG_RUNTIME_DIR if it is set, otherwise it will be put in ~/.netlogo/7.0. You can also see the exact path in the console output.

ERSUCC and others added 30 commits January 25, 2026 23:02
It overcomplicates app initialization, leads to confusing runtime errors, and prevents multiple models from being open at the same time
Also fixes a bug where Cmd+Q bypassed NetLogo's quit method
@kgmt0
Copy link
Copy Markdown
Contributor Author

kgmt0 commented Feb 8, 2026

P.S.: In retrospect, although I find this extremely cool and potentially very useful to me for my side projects, it's not clear to me how the average NetLogo user would be intended to access this functionality. I've never encountered any mention of named pipes outside of the Win32 API docs. Maybe I misunderstood the intended purpose of this remote control feature?

The idea is that this will be used by an editor plugin so that you can do things like running setup and go without leaving your editor. The plugin would be responsible for discovering these sockets and sending the commands on behalf of the user. In the case that there are multiple sockets, it could use some heuristics to decide which socket to use or just directly ask the user (preferably presenting them as something more user-friendly than just the socket paths). Ideally, the user wouldn't need to know that these sockets exist at all.

@kgmt0 kgmt0 force-pushed the remote-commands branch 3 times, most recently from 7183f0d to 3b3d22f Compare February 11, 2026 09:14
@ERSUCC
Copy link
Copy Markdown
Contributor

ERSUCC commented Feb 11, 2026

@kgmt0 Unfortunately, this new library is even worse on Windows than the last one. I don't get any exception dialogs when toggling the preference or starting up NetLogo, but I am no longer able to connect to the pipe. If I use your solution as is, it says it can't access the file, presumably because pipes are supposed to be created at \\.\pipe\... instead of in an arbitrary location. But if I change the code to create the pipe in the correct location, it fails to create one at all. Am I supposed to use a different method of connecting to the socket with this new library?

@kgmt0
Copy link
Copy Markdown
Contributor Author

kgmt0 commented Feb 11, 2026

Am I supposed to use a different method of connecting to the socket with this new library?

Yes, it turns out Windows supports Unix sockets now, so I just used Unix sockets on all OSes. But since there's no longer any need for platform-specific code, I'm thinking I might as well just use the Java standard library and create the socket myself. I'll update the PR if that goes well.

@kgmt0 kgmt0 marked this pull request as draft February 11, 2026 21:22
@ERSUCC
Copy link
Copy Markdown
Contributor

ERSUCC commented Feb 11, 2026

Ah ok, fantastic! Thanks for the clarification.

@kgmt0
Copy link
Copy Markdown
Contributor Author

kgmt0 commented Feb 13, 2026

It looks like switching to just using the Java standard library would be more work than I thought. For some reason, Unix sockets only work with ServerSocketChannel, and the API is quite a bit lower level than ServerSocket that I'm currently using, so I think it's worth using a library here.

@kgmt0 kgmt0 changed the base branch from main to wip-7.1 February 13, 2026 02:24
@kgmt0 kgmt0 marked this pull request as ready for review February 13, 2026 02:25
This creates a Unix socket (or a named pipe on Windows) that listens to
commands. An external editor can use this socket to send commands for
NetLogo to run.
@ERSUCC ERSUCC force-pushed the wip-7.1 branch 7 times, most recently from 30fc104 to ac39ffb Compare February 27, 2026 17:36
@ERSUCC ERSUCC force-pushed the wip-7.1 branch 2 times, most recently from bfd5da7 to 4087ac8 Compare March 13, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants