luasocket/samples/talker.lua

22 lines
725 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
-- RCS ID: $Id$
-----------------------------------------------------------------------------
2004-06-21 06:07:58 +00:00
local socket = require("socket")
2001-01-25 21:57:07 +00:00
host = host or "localhost"
port = port or 8080
2000-12-29 22:15:09 +00: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 22:44:00 +00:00
c = assert(socket.connect(host, port))
2000-12-29 22:15:09 +00:00
print("Connected! Please type stuff (empty line to stop):")
2003-05-25 01:54:13 +00:00
l = io.read()
2000-12-29 22:15:09 +00:00
while l and l ~= "" and not e do
2005-01-02 22:44:00 +00:00
assert(c:send(l .. "\n"))
2003-05-25 01:54:13 +00:00
l = io.read()
2000-12-29 22:15:09 +00:00
end