企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~lua|woo print("websockets测试(onMessage每次读取的字节大小为最大10KB,超过10KB请使用变量来统计):", 0xa) local wsock = woo.ws:new() local index = 0 wsock :with({ onMessage = function(len, bytes) _out('得到ws服务器返回字节集长度:', len, '\n') _out('得到ws服务器返回字节集转换为字符串:', _byte_str(bytes), '\n') wsock:write("再给你条消息" .. index) index = index + 1 if index > 2 then return true -- 这里返回true,即可停止读取 end end, onOpen = function() _out('拨通远程ws-ip链接状态:', r, '\n') r = wsock:write("你好服务器") _out('ws写入长度:', r, '\n') end, onClose = function() if not wsock:reConnect() then print('reConnect fail,exit') return true end end, onError = function(err) _out('得到错误信息:', err) end }):dial("ws://123.207.136.134:9010/ajaxchattest", "http://123.207.136.134:9010/") ~~~