luasocket/samples/talker.lua

22 lines
774 B
Lua
Raw Normal View History

-----------------------------------------------------------------------------
-- TCP sample: Little program to send text lines to a given host/port
-- LuaSocket sample files
-- Author: Diego Nehab
2012-04-11 22:21:25 +02:00
-- RCS ID: $Id: talker.lua,v 1.9 2005/01/02 22:44:00 diego Exp $
-----------------------------------------------------------------------------
2004-06-21 08:07:58 +02:00
local socket = require("socket")
2001-01-25 22:57:07 +01:00
host = host or "localhost"
port = port or 8080
2000-12-29 23:15:09 +01:00
if arg then
host = arg[1] or host
port = arg[2] or port
end
print("Attempting connection to host '" ..host.. "' and port " ..port.. "...")
2005-01-02 23:44:00 +01:00
c = assert(socket.connect(host, port))
2000-12-29 23:15:09 +01:00
print("Connected! Please type stuff (empty line to stop):")
2003-05-25 03:54:13 +02:00
l = io.read()
2000-12-29 23:15:09 +01:00
while l and l ~= "" and not e do
2005-01-02 23:44:00 +01:00
assert(c:send(l .. "\n"))
2003-05-25 03:54:13 +02:00
l = io.read()
2000-12-29 23:15:09 +01:00
end