2003-06-09 20:23:40 +02:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- TCP sample: Little program to send text lines to a given host/port
|
2003-06-26 20:47:49 +02:00
|
|
|
-- LuaSocket sample files
|
2003-06-09 20:23:40 +02:00
|
|
|
-- Author: Diego Nehab
|
|
|
|
-- RCS ID: $Id$
|
|
|
|
-----------------------------------------------------------------------------
|
2004-05-30 23:36:22 +02:00
|
|
|
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.. "...")
|
2004-05-30 23:36:22 +02:00
|
|
|
c = socket.try(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
|
2004-05-30 23:36:22 +02:00
|
|
|
socket.try(c:send(l, "\n"))
|
2003-05-25 03:54:13 +02:00
|
|
|
l = io.read()
|
2000-12-29 23:15:09 +01:00
|
|
|
end
|