You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
776 B
38 lines
776 B
local socket = require'socket'
|
|
local sync = require'websocket.sync'
|
|
local tools = require'websocket.tools'
|
|
|
|
local new = function(ws)
|
|
ws = ws or {}
|
|
local self = {}
|
|
|
|
self.sock_connect = function(self,host,port)
|
|
self.sock = socket.tcp()
|
|
if ws.timeout ~= nil then
|
|
self.sock:settimeout(ws.timeout)
|
|
end
|
|
local _,err = self.sock:connect(host,port)
|
|
if err then
|
|
self.sock:close()
|
|
return nil,err
|
|
end
|
|
end
|
|
|
|
self.sock_send = function(self,...)
|
|
return self.sock:send(...)
|
|
end
|
|
|
|
self.sock_receive = function(self,...)
|
|
return self.sock:receive(...)
|
|
end
|
|
|
|
self.sock_close = function(self)
|
|
--self.sock:shutdown() Causes errors?
|
|
self.sock:close()
|
|
end
|
|
|
|
self = sync.extend(self)
|
|
return self
|
|
end
|
|
|
|
return new
|
|
|