How to start SOCAT when Octoprint is connecting?

I built an ESP3D interface on my printer, and want to automatically start SOCAT on the Linux system I run Octoprint on, when I CONNECT to my printer.
Socat is used to map a TCP/IP connection as serial interface, so Octoprint can talk to my printer over WiFi (my local network). However, socat stops when I switch off my printer, as then also the WiFi connection to the EPS3D stops.
So to print, I switch on the printer and the wifi device, then run socat on my Linux server
socat -d -d pty,raw,link=/dev/virtualcom0,user="xxx", tcp:"":"8888"
and then start Octoprint and connect to my printer.

Have Octoprint run a custom command, in this case the socat line, when I click Connect. And kill socat when I disconnect. I know that I can run custom G-code commands on (dis)connecting, but it seems like I cannot run system commands on those events. That would be a way to implement this.

Or can I make a plugin to do this (apart from the fact that I don't know how to create a plugin)?