Is communication possible with the 3D slicer's python console?

Operating system: window 10
Slicer version: 5.2.1

Hello , 3D slicer users
With your help, my project has been successfully completed.
The second project is communication.

I’m going to create a Python module that communicates between admin-client.

  • admin: Distribute tasks to clients
  • client : Sends the task to the admin when the task is complete

The question is, I want to configure this module as a slicer extension module so that it works on the python console within the 3D slicer. Is this possible?
Does 3d slicer have support for communication module?

Yes, there are many ways to do this. It will help people understand your goals better if you clarify what type of communication you have in mind (raw tcp, http, other?). And what exactly is the admin program and what is the client (are they both Slicer instances? are they other programs?).

It might help if you look at the WebServer module, which can allow other programs, perhaps your admin program, to control the operation of a Slicer instance, perhaps your client.

1 Like

Thank you for quick response.

Nothing has been decided yet, but I first wondered if communication was possible in the Python console of the 3D slicer.

Yes. Both work only in slicer.

If I deduce my boss’ thoughts, it seems to create a Python module that works with a 3D slicer, and
the client that has finished the work sends the completed slicer task to the admin.

After reading the article you recommended and understanding the concept as much as possible, I will try to ask more detailed questions. thanks for the quick reply

Then yes, using something like the requests module from the admin Slicer instance can allow you to connect to an arbitrary number of client Slicer instances (assign unique tcp ports to each) via the WebServer and the exec API to run python code in the client. Let us know how it works for you.

1 Like

Okay I’ll try it , see you later !

Is the ‘https’ protocol possible?

Yes, when you instantiate the server you can supply a certificate. If you are in a controlled network or the same machine this is really optional. If you are using multiple machines on an open network I suggest creating ssh tunnels instead for security rather than relying on network traffic even if it is encrypted. Web server security is a big topic, so be thoughtful about what you expose.

1 Like

@pieper Hi again

I want to make a toy project before making a communication module.
What should I refer to to do the task below?

  • Transfer slicer tasks (add markups, etc…) from your computer to your colleague’s computer
  • When you open the transferred file on your colleague’s computer, check if it is the same as the file you worked on on your computer.

Would it be good to refer to ‘OpenIGTLink Python package’ ?

Hard to say, but if your goal is to transfer this task to a human being who will use slicer to do something like segmentation and then give you back the result it may be easier to use .mrb files with a shared network directory or a system like dropbox. You can make some small scripts if you want to automate this and check that the results are in the right format.

OpenIGTLink is for continuous real-time data like video or 3D tracker data.

The WebServer would allow real-time control of one Slicer instance from another, but maybe not as logical to use when there are human beings involved on the client computer.

If the task is AI related, you may consider the MONAILabelReviewer module.

Honestly, I’ve never done anything other than data engineering and AI model building, so even looking at the network documentation you linked to, I don’t quite understand.

Q1. The basic framework of the server is already built, and am I adding various options with a command?

some_slicer_server_build_command( security_protocol_params, etc, .. ) 

Can you give me a code example of building a server and sending and receiving simple data?

If I know the command to turn on the server and send and receive data in the Slicer’s Python console, I think I can do something based on this, but I don’t know how.