-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathws.lua
More file actions
34 lines (27 loc) · 804 Bytes
/
ws.lua
File metadata and controls
34 lines (27 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local skynet = require "skynet"
local class = require "class"
local ws = class("ws")
function ws:ctor (opt)
self.ws = opt.ws -- websocket对象
self.headers = opt.headers -- http headers
self.send_masked = false -- 掩码(默认为false, 不建议修改或者使用)
self.max_payload_len = 65535 -- 最大有效载荷长度(默认为65535, 不建议修改或者使用)
end
function ws:on_open ()
self.state = true
self.count = 1
skynet.error("客户端已连接")
end
function ws:on_message (msg, type)
-- 客户端消息
skynet.error("客户端发送消息:", msg, type)
end
function ws:on_error (msg)
-- 错误消息
skynet.error("错误的消息:", msg)
end
function ws:on_close (msg)
-- 清理数据
skynet.error("客户端断开了连接:", msg)
end
return ws