client:connect_to_host_async('localhost', 6666, nil, function (client, result) local connection = client:connect_to_host_finish(result) if connection == nil then return end local ostream = connection:get_output_stream() local istream = Gio.DataInputStream.new(connection:get_input_stream()) ostream:write_all_async([[GET / HTTP/1.1 ]], GLib.PRIORITY_DEFAULT, nil, function(ostream, result) ostream:write_all_finish(result) ostream:close() end) local lines = {} local last_line = '' local i = 0 line_callback = function (istream, result) last_line = istream:read_line_finish(result) if last_line ~= nil then table.insert(lines, last_line) istream:read_line_async(GLib.PRIORITY_DEFAULT, nil, line_callback) else print(table.concat(lines, '\n') .. '\n') end end istream:read_line_async(GLib.PRIORITY_DEFAULT, nil, line_callback) end)