Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two way communication between a computer and another server #5

Open
C-Bookie opened this issue Jan 16, 2021 · 2 comments
Open

Two way communication between a computer and another server #5

C-Bookie opened this issue Jan 16, 2021 · 2 comments

Comments

@C-Bookie
Copy link

I've been attempting to understand how to I could wait on my own socket connection to another server, before triggering some computercraft command, however I keep running into issues with greenlet. As I understand it, I can't call any computercraft functions form another coroutine listening to a socket, otherwise I'll encounter the error 'Computercraft function was called outside context'.
If I did find some way to wait for the signal in the current greenlet, then I assume I'd be blocking communication with the computercraft computer.

As a proof of concept, I just want to trigger a redstone signal using a websocket connection with a separate server. Is there any simple approach to this?

@neumond
Copy link
Owner

neumond commented Jan 17, 2021

The problem is that it's always minecraft/lua side which asks python side to execute something. And this execution on python side should be as short as possible, similarly to actual mod mechanics: infinite loop in lua will load server CPU until the mod automatically kills it. There's no easy way to ask lua side to execute something, you have to distinguish between 1. several minecraft servers 2. several CC computers on server 3. each computer may have several threads of execution (all of these is actually a context). On top of that, CC computers may be disconnected from python side at the moment (e.g. turned off, or py program has been stopped).

For your case with redstone, we need a way to reuse existing http.websocket lua API without interference with python-computer-craft. This requires some work from my side. Since this repo gains some interest, I think I'll spare more time on it, but don't expect patches too soon.

@C-Bookie
Copy link
Author

Hay, don't know if this is still intended development but I wouldn't mind having a crack at it on a fork if you've an idea of how I should approach it. I do have to ask, why the change from pure asyncio to greenlet?

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

No branches or pull requests

2 participants