2

i am realy struggling to connect and read from a existing unix file socket.

the socket exist, is Mode +rwx and should return a json oneliner (without newline).

(i have no Problem to read the socket on debian based systems like ncat -U /run/fastd.supernode.sock)

While i try to solve it on a embedded device TP-Link841v11-ND Mips (Fastd Socket on an OpenWRT / LEDE Router from TP Link) mainly only lua (and luasocket) is available. i come so far

$ lua
> socket = require"socket"
> socket.unix = require"socket.unix"
> getme = socket.unix("/var/run/fastd.mesh_vpn.socket")
> print(getme:receive())
stdin:1: calling 'receive' on bad self (unix{client} expected, got userdata)
stack traceback:
    [C]: in function 'receive'
    stdin:1: in main chunk
    [C]: ?

solution, for those who have similar problems

(as described here https://forum.freifunk.net/t/connect-fastd-socket-on-tp841v11-fastd-statistiken/13499 )

(you need to reconnect each time you wanna read socket)

$ lua
> require "socket"
> require "socket.unix"
> c = socket.unix()
> c:connect("/var/run/fastd.mesh_vpn.socket")
> print(c:receive())
  • Replace first two line with a single `unix = require 'socket.unix'`, and `getme=unix"/var/run...sock"` – hjpotter92 Sep 10 '16 at 05:03
  • may be you need call connect method. e.g. `s=socket.unix();s:connect('path here')`? Never try this socket type. – moteus Sep 10 '16 at 06:30

1 Answers1

0

You are missing several commands; see the complete example in this SO answer or this maillist discussion for further details.

Community
  • 1
  • 1
Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • yes, i saw this - but there they deal with writing into a socket and that confused a lot - but thx nevertheless .. now i break this down to a bare minimum – jens viisauksena Sep 10 '16 at 07:33
  • I recommend using luaposix instead — see [my answer](https://stackoverflow.com/a/65569899/148195) to a similar question. – mk12 Jan 04 '21 at 21:20