# Create\_local\_server Example?

**URL:** <https://forum.qoitech.com/t/create-local-server-example/188>\
**Category:** Support\
**Created:** [July 13, 2018, 3:05pm UTC](https://forum.qoitech.com/t/create-local-server-example/188 "2018-07-13T15:05:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![philware](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@philware](https://forum.qoitech.com/u/philware)\
**Post date:** [July 13, 2018, 3:05pm UTC](https://forum.qoitech.com/t/create-local-server-example/188/1 "2018-07-13T15:05:03Z")

</div>

Hi,

I wish to be able to control Otii with another application, not just scripting through Lua inside Otii.

I see there is a event\_loop.lua example which creates a local server (?) - but I can’t see how I can send commands to this server from another application.

Is this what it is used for?

Thanks,  
Phil.

---

<div class="post-metadata">

**Author:** ![chrfle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.qoitech.com/chrfle/32/288_2.png) [@chrfle](https://forum.qoitech.com/u/chrfle)\
**Post date:** [July 13, 2018, 10:00pm UTC](https://forum.qoitech.com/t/create-local-server-example/188/2 "2018-07-13T22:00:00Z")

</div>

Yes, you can use this to open a named socket which an other application can connect to and send commands that your Lua script will act upon. I’ll use the [event\_loop.lua](https://www.qoitech.com/help/scripting/examples/event_loop.lua.html) script as example here.

On linux you can send things to it by using netcat for example.

> nc -U /tmp/com.qoitech.otiicli

Then you can write commands, for example ‘on’ and ‘start’. Please note that you need to terminate the command with an EOF signal and not a newline. On linux you can produce a EOF by pressing CTRL+D.

In python you use the socket module.

> import socket  
> s = socket.socket(socket.AF\_UNIX, socket.SOCK\_STREAM)  
> s.connect(“/tmp/com.qoitech.otiicli”)  
> s.send(‘start’.encode(‘utf-8’))

This will send ‘start’ to the Lua script.

I know this is possible to do on Windows as well. On a recent windows 10 you should have AF\_UNIX support according to this [article](https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/) by Microsoft.

Before that it might be named pipes that are used. You can read more about that [here](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx). I’ll try to get a confirmation from someone in the team that knows windows better than me on Monday.

Hope this helps, and don’t hesitate to ask additional questions.

---

<div class="post-metadata">

**Author:** ![philware](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@philware](https://forum.qoitech.com/u/philware)\
**Post date:** [July 16, 2018, 11:23am UTC](https://forum.qoitech.com/t/create-local-server-example/188/3 "2018-07-16T11:23:27Z")

</div>

Thanks for your clear answer. I didn’t realise it was named pipes.

---

<div class="post-metadata">

**Author:** ![chrfle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.qoitech.com/chrfle/32/288_2.png) [@chrfle](https://forum.qoitech.com/u/chrfle)\
**Post date:** [July 16, 2018, 11:24am UTC](https://forum.qoitech.com/t/create-local-server-example/188/4 "2018-07-16T11:24:30Z")

</div>

Let us know if you have any further questions.

---

<div class="post-metadata">

**Author:** ![vkuronen](https://avatars.discourse-cdn.com/v4/letter/v/e95f7d/32.png) [@vkuronen](https://forum.qoitech.com/u/vkuronen)\
**Post date:** [September 4, 2018, 2:26pm UTC](https://forum.qoitech.com/t/create-local-server-example/188/5 "2018-09-04T14:26:38Z")

</div>

In MacOs the named unix domain socket is a bit tricky to find, but e.g. with Python, the psutils is quite handy for this, providing platform independent solution. Example:

> import psutil  
> servername=“com.qoitech.otiicli”  
> path = [sock.laddr for sock in psutil.net\_connections(‘unix’) if servername in sock.laddr][0]  
> s.connect(path)

sockets in MacOs can be found with netstat as in Linux but they seem to locate like following example:

> /var/folders/s2/59\_18lj51w32yknwxwksdnr548n585/T/com.qoitech.otiicli’
