模块 socket
require "socket"
公开 API
| API | 实现 | 说明 |
|---|---|---|
socket:connect | S_connect | 连接到主机/端口 |
socket:send | S_send | 发送数据 |
socket:receive | S_receive | 接收数据(pattern 可为 '*l'/'*a'/数字) |
socket:bind | S_bind | 绑定本地地址/端口 |
socket:listen | S_listen | 开始监听(TCP 服务端) |
socket:accept | S_accept | 接受一个连接,返回新套接字 |
socket:settimeout | S_settimeout | 设置收发超时(秒) |
socket:setoption | S_setoption | 设置套接字选项:setoption("tcp_nodelay"|"keepalive"|"reuseaddr"|"broadcast"|"dontroute", value) |
socket:getpeername | S_getpeername | 返回远端地址 (host, port) |
socket:getsockname | S_getsockname | 返回本地地址 (host, port) |
socket:shutdown | S_shutdown | 半关闭连接:shutdown(how?),how 0=收 1=发 2=收发(默认) |
socket:close | S_close | 关闭套接字 |
socket.tcp | S_tcp | 创建 TCP 客户端套接字对象 |
socket.udp | S_udp | 创建 UDP 套接字对象 |
socket 还提供 QUIC 子模块 socket.quic(RFC 9000,quinn + rustls TLS 1.3):查看 quic 文档