lua-socket: unix domain sockets? -
i'm using lua-socket 3.0rc1.3 (that comes ubuntu trusty) , lua 5.1. i'm trying listen on unix domain socket, , example code can find this
-- send stdin through unix socket socket = require"socket" socket.unix = require"socket.unix" c = assert(socket.unix()) assert(c:connect("/tmp/foo")) while 1 local l = io.read() assert(c:send(l .. "\n")) end problem is, when try , connect() "no such file or directory" - how create socket in first place? mkfifo /tmp/foo recommended me gets me "connection refused" error instead (i don't think fifo same thing domain socket?).
is there minimal working example out there of using luasocket on unix domain socket?
edit: paul's solution, here's mwe if anyone's interested
libsocket = require "socket" libunix = require "socket.unix" socket = assert(libunix()) socket="/tmp/socket" assert(socket:bind(socket)) assert(socket:listen()) conn = assert(socket:accept()) while 1 data=assert(conn:receive()) print("got line: " .. data) conn:send("echo: " .. data .. "\n") if data == "." conn:close() return end end
as far understand, can't create socket using mkfifo (or command) created (listening) server. there example listed on same page referenced, may difficult find:
sock, err = s:listen([backlog|_32_]) sock, err = s:bind(path) client_conection, err = s:accept() basically, create server same way you'd tcp, instead of binding address/port, bind path , start accepting new connections on it.
Comments
Post a Comment