I have the following python code that I am trying to adapt to nim
import socket
import os
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect("\0termux-input")
client.send("{'api_method':'Dialog','input_method':'text'}".encode('utf-8'))
Here is my nim code
import net
let sock = newSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)
# also tried prefixing \0 to the path
sock.connectUnix("termux-input")
sock.send("{'api_method':'Dialog','input_method':'text'}")
But I get a connection refused on connection.
tapi.nim(5) tapi
net.nim(943) connectUnix
oserr.nim(110) raiseOSError
Error: unhandled exception: Connection refused [OSError]
Does anyone have any pointers on how I can debug this?
Then dive into the stdlib, specifically the spot where connectUnix is defined and fix it :)
Thanks for the useful infomation.
connect(3, {sa_family=AF_UNIX, sun_path=@"termux-input\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 110) = -1 ECONNREFUSED (Connection refused)
Prefixing 0 adds the @ required for sun_path but is also appends several 0's to the end of the string (very strange).