lua 中 socket 通信示例
server.lua
#!/usr/bin/lua
local socket = require("socket")
host, port = "127.0.0.1", 9090
server = assert(socket.bind(host, port))
ack = "ack\n"
while true
do
print("server: waiting for client connection ...")
control = assert(server:accept())
while true
do
command, status = control:receive()
if status == "closed" then
break
end
print(command)
control:send(ack) -- 注意:发送的数据必须要有结束符才能发送成功
end
end
client.lua
#! /usr/bin/lua
local socket = require("socket")
host, port = "127.0.0.1", 9090
client = assert(socket.connect(host, port))
client:send("GET\n")
while true
do
local s, status, partial = client:receive()
print(s)
if status == "closed" then
break
end
client:send("GET\n")
end
client:close()
最新文章
- SQL Server2014 SP2关键特性
- Tomcat服务器本地的搭建,以及在 IDEA软件下的配置,以及项目的测试运行(基于supermvc框架下的web)
- PHP读写大“二进制”文件,不必申请很大内存(fopen、fread、fwrite、fclose)
- Java学习笔记,前两章总结
- LeetCode——Reverse Integer(逆置一个整数)
- C#泛型简化代码量示例
- Qt工具知多少(一目了然)
- nagios监控linux设置
- 《RPM源码包的制作》RHEL6
- Bootstrap_排版_标题
- (一)CodeMirror - 基本应用
- [PCB设计] 3、用CAM350修改GERBER文件(删除某些部分)
- CAP 2.4版本发布,支持版本隔离特性
- TextField
- RS485 VS 20mA 电流环
- windows保存的文件传输到linux中格式转换
- ES6 promise学习笔记 -- 基本用法
- db2文件系统已满
- 虚拟机上不能使用CUDA
- linux c++环境