local socket = require 'socket' local s = socket.tcp() s:settimeout(1, 't') -- 1000ms s:connect('localhost', 9000) local line, err = s:receive '*l' while line ~= nil do print(line) line, err = s:receive '*l' end if err ~= nil and err ~= 'closed' then print('uh-oh: ' .. err) end s:shutdown 'both'