mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
add network.tcp_connect and .tcp_open
This commit is contained in:
parent
847ef23092
commit
34974c4bb3
3 changed files with 63 additions and 15 deletions
|
|
@ -34,3 +34,28 @@ cameras.get = function(name)
|
|||
wrappers[name] = wrapper
|
||||
return wrapper
|
||||
end
|
||||
|
||||
|
||||
local Socket = {__index={
|
||||
send=function(self, bytes) return network.__send(self.id, bytes) end,
|
||||
recv=function(self, len, usetable) return network.__recv(self.id, len, usetable) end,
|
||||
close=function(self) return network.__close(self.id) end,
|
||||
}}
|
||||
|
||||
network.tcp_connect = function(address, port, callback)
|
||||
local socket = setmetatable({id=0}, Socket)
|
||||
return setmetatable({id=network.__connect(address, port, function(id)
|
||||
socket.id = id
|
||||
callback(socket)
|
||||
end)}, Socket)
|
||||
end
|
||||
|
||||
local ServerSocket = {__index={
|
||||
close=function(self) return network.__closeserver(self.id) end,
|
||||
}}
|
||||
|
||||
network.tcp_open = function(port, handler)
|
||||
return setmetatable({id=network.__open(port, function(id)
|
||||
handler(setmetatable({id=id}, Socket))
|
||||
end)}, ServerSocket)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue