I'm using lua-socket 3.0rc1.3 (that comes with Ubuntu Trusty) and lua 5.1. I'm trying to listen on a unix domain socket, and the only example code I can find is 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 do
local l = io.read()
assert(c:send(l .. "\n"))
end
Problem is, when I try and connect()
I get "no such file or directory" - how do I create that socket in the first place? mkfifo /tmp/foo
which someone recommended me gets me a "connection refused" error instead (I don't think a fifo is the same thing as a domain socket?).
Is there any minimal working example out there of using luasocket on a unix domain socket?
EDIT: from Paul's solution, here's a 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 do
data=assert(conn:receive())
print("Got line: " .. data)
conn:send("echo: " .. data .. "\n")
if data == "." then conn:close() return end
end