Mercurial > luasocket
comparison samples/echoclnt.lua @ 0:4b915342e2a8
LuaSocket 2.0.2 + CMake build description.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 26 Aug 2008 18:40:01 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4b915342e2a8 |
---|---|
1 ----------------------------------------------------------------------------- | |
2 -- UDP sample: echo protocol client | |
3 -- LuaSocket sample files | |
4 -- Author: Diego Nehab | |
5 -- RCS ID: $Id: echoclnt.lua,v 1.10 2005/01/02 22:44:00 diego Exp $ | |
6 ----------------------------------------------------------------------------- | |
7 local socket = require("socket") | |
8 host = host or "localhost" | |
9 port = port or 7 | |
10 if arg then | |
11 host = arg[1] or host | |
12 port = arg[2] or port | |
13 end | |
14 host = socket.dns.toip(host) | |
15 udp = assert(socket.udp()) | |
16 assert(udp:setpeername(host, port)) | |
17 print("Using remote host '" ..host.. "' and port " .. port .. "...") | |
18 while 1 do | |
19 line = io.read() | |
20 if not line or line == "" then os.exit() end | |
21 assert(udp:send(line)) | |
22 dgram = assert(udp:receive()) | |
23 print(dgram) | |
24 end |