local spawn = require('childprocess').spawnlocal net = require('net')
local args = { "-M", "-D", "hw:0,1", "-t", "raw", "-c", "2", "-r", "48000", "-f", "S16_LE",}
local socksock = net.Socket:new()
local function doConnect() print("Connecting...")
sock:connect(1234, '192.168.1.157')end
local function onConnect() print("Connected") local arecord
arecord = spawn("arecord", args)
arecord:on("error", function(err) print("Spawn error:", err) end) arecord:on("exit", function(exit_status) print("Exit with " .. exit_status) end)
arecord.stdout:pipe(sock) arecord.stderr:pipe(sock)end
local function onError(err) print("Socket error:", err) if err == 'ECONNREFUSED' then sock:setTimeout(1000, doConnect) elseif err == 'EPIPE' then sock:setTimeout(1000, doConnect) end end sock:on("connect", onConnect)sock:on("error", onError) doConnect()
--
You received this message because you are subscribed to the Google Groups "luvit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to luvit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hey Jörg,In your doConnect function you will want to instantiate a new socket there. You can't reuse the same socket instance.
local fs = require('fs')
local spawn = require('childprocess').spawnlocal net = require('net')
local args = { "-M",
"-D", "record_left", "-t", "raw", "-c", "1",
"-r", "48000", "-f", "S16_LE",}
local function doConnect() local arecord local sock
local ip = "192.168.0.101" local port = 1234
if not ip or not port then return end
print(string.format("Connecting to %s:%s", ip, port)) sock = net.createConnection(port, string.format("%s", ip))
sock:on("connect", function (err) if err then print("Connection error:", err) end print("Connected")
arecord = spawn("arecord", args)
arecord:on("error", function(err) print("Spawn error:", err) end) arecord:on("exit", function(exit_status) print("Exit with " .. exit_status)
sock:setTimeout(1000, doConnect) end)
arecord.stdout:on('data', function(data) sock:write(data) end) arecord.stderr:pipe(process.stderr) end)
sock:on("error", function(err) if err then
print("Socket error:", err)
if arecord then arecord:kill('sigkill') else
sock:setTimeout(1000, doConnect) end end
end)end
doConnect()
To unsubscribe from this group and stop receiving emails from it, send an email to luvit+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to luvit+unsubscribe@googlegroups.com.