Internal server for FreeCAD

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Internal server for FreeCAD

Post by Zolko »

freedman wrote: Thu Oct 14, 2021 5:27 am I don't know if this makes any difference to your coding but could you please presume that someone will want to remove something like this later. I want someday for FreeCAD to go into the school system and stand alone operation is a big advantage. I plan to remove all internet connection code and anything that connects machines.
not only schools but any sensitive design material in any normal company.

dcapeletti wrote: Thu Oct 14, 2021 8:13 am Hello, you can create your FreeCAD branch and delete what you don't want.
This is not logical: rather create your own branch and add your bloat there, but leave the main FreeCAD code clean. Better still: make an addon workbench, but don't add security nightmares to everyone.
try the Assembly4 workbench for FreCAD — tutorials here and here
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Internal server for FreeCAD

Post by wmayer »

dcapeletti wrote: Wed Oct 13, 2021 7:06 pm Hi, I downloaded the weekly-builds version and I confirm that it works! But apparently it does not work, when I start FreeCAD with -c in console mode the server does not respond to the client.

Regards
That's now supported with git commit 39e02ca195d

In the terminal window where FreeCAD is running you call

Code: Select all

port = 12345
timeout = -1
import Web
Web.waitForConnection("localhost", port, timeout)
and in the client window you run the requests as usual.

Note, that waitForConnection() only handles one request and afterwards the interpreter leaves the function. If you want the server to run permanently you have to run the function in an endless loop.
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Internal server for FreeCAD

Post by freedman »

dcapeletti wrote
Hello, you can create your FreeCAD branch and delete what you don't want. Anyway it is less work to block FreeCAD in the firewall so that it cannot create connections or receive requests from outside. That way you will be 100% sure that there is no code out there that can create random connections.
Let's change that "100% sure" to 99% sure since the firewall is just another piece of software. I know a IT guy at a school and the words trust and software don't go together very often. In these times, I presume nothing is secure unless it's not powered. :)

I was just thinking that if you had awareness, that might prompt a few more code comments.
Thank you
User avatar
dcapeletti
Posts: 504
Joined: Wed Jul 23, 2014 2:27 pm

Re: Internal server for FreeCAD

Post by dcapeletti »

freedman wrote: Thu Oct 14, 2021 2:07 pm Let's change that "100% sure" to 99% sure since the firewall is just another piece of software. I know a IT guy at a school and the words trust and software don't go together very often. In these times, I presume nothing is secure unless it's not powered. :)

I was just thinking that if you had awareness, that might prompt a few more code comments.
Thank you
Hi, even if you are wary of the firewall, you can disconnect it from the internet and use it on an intranet since not only FreeCAD can connect to the outside but hundreds of operating system programs that start much earlier or even programs that you use daily, such as office or graphic design programs.

There are programs and hardware that if they don't connect to each other don't make much sense on their own, but there are things that do make a lot of sense to be connected.

What I/we are looking for with this functionality is to create a kind of Input/Output API for bidirectional communication with FreeCAD and the outside world. That FreeCAD can serve as a hardware state representation system showing in 3D view the reality and at the same time as an interface to control the machines. That is, it can receive signals from the outside (sensors) or send signals to controllers to move motors, hydraulics, etc.. All this is reflected in the 3D model. This makes a lot of sense in many industries like IOT or Digital Twins, home automation, robotics where it is important that the 3D model reflects the state of the hardware and processes, see https://www.youtube.com/watch?v=iVS-AuSjpOQ

You even want to connect FreeCAD with Libreoffice or Blender, you could do it through this functionality.

Regards
User avatar
dcapeletti
Posts: 504
Joined: Wed Jul 23, 2014 2:27 pm

Re: Internal server for FreeCAD

Post by dcapeletti »

wmayer wrote: Thu Oct 14, 2021 1:52 pm That's now supported with git commit 39e02ca195d
Thanks, I will try it in the next week.

I wonder, now that the Read and Write functionality is integrated, will it be possible on the server side to list the connected clients and send them messages, for example if the model state changes notify them of the change. I would do this with a document observer, but I would like there to be a server function to notify interested clients of changes, something similar to what I have done in this video https://youtu.be/Ta3nfMsbhDE?t=302

Thanks
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Internal server for FreeCAD

Post by wmayer »

I wonder, now that the Read and Write functionality is integrated, will it be possible on the server side to list the connected clients and send them messages, for example if the model state changes notify them of the change.
No. The way how it works at the moment is that if the client sends a request to the FreeCAD server it will reply back immediately and then closes the connection.
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Internal server for FreeCAD

Post by freedman »

dcapeletti » Sat Oct 16, 2021 10:25 am
That is, it can receive signals from the outside (sensors) or send signals to controllers to move motors, hydraulics, etc.. All this is reflected in the 3D model. This makes a lot of sense in many industries like IOT or Digital Twins, home automation, robotics where it is important that the 3D model reflects the state of the hardware and processes, see https://www.youtube.com/watch?v=iVS-AuSjpOQ
For my home stuff that sounds great!
At the facility level; they end up with machines with many additions including Wifi and Bluetooth all integrated. I have seen machines that come in with built-in Verizon/Att cell cards. The IT person can switch off the hardware but only in software (on laptops and tablets) so that leaves a big security hole. Many times computer systems get donated or granted to a school system so they end up kind of stuck. I know it's only a matter of time for all the modern protocols to get added so I'm not against that, I just know someday I will try to remove them.
Thanks again
User avatar
dcapeletti
Posts: 504
Joined: Wed Jul 23, 2014 2:27 pm

Re: Internal server for FreeCAD

Post by dcapeletti »

wmayer wrote: Thu Oct 14, 2021 1:52 pm That's now supported with git commit 39e02ca195d

In the terminal window where FreeCAD is running you call

Code: Select all

port = 12345
timeout = -1
import Web
Web.waitForConnection("localhost", port, timeout)
and in the client window you run the requests as usual.

Note, that waitForConnection() only handles one request and afterwards the interpreter leaves the function. If you want the server to run permanently you have to run the function in an endless loop.

Thank you very much, I confirm that it works.
For the type of development I am doing, it is important that the connection is maintained so that when the observer hears a change, it reports back to the connected clients. For that I am developing a macro with these features based on client server sockets. Here is a test gif https://gitlab.com/dcapeletti/freecad-s ... n/demo.gif

Now I am thinking how to model this, a macro is just the beginning to demonstrate the idea.

Regards
Post Reply