File size: 1,405 Bytes
d7c5875 | 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | local snet = {}
local socket = require("socket")
snet._VERSION = "SNET v.1.0.1"
snet._COPYRIGHT = "Copyright © 2020 Pavel Akulichev"
snet._DESCRIPTION = "Simple Network Module v.1.0.1"
-- SNET Statuses Definition
SNET_DISCONNECTED = 0
SNET_CONNECTED = 1
-- SNET Priorities
SNET_SYSTEM_PRIORITY = 4
SNET_HIGH_PRIORITY = 3
SNET_MEDIUM_PRIORITY = 2
SNET_LOW_PRIORITY = 1
SNET_BYPASS_PRIORITY = 0
-- SNET Service Packet IDs
SNET_CONFIRM_PRIORITY = 0xFFFFFFFF
SNET_BLOCK_PACKET = 0xFFFFFFFF - 1
snet.bstream = require("snet.bstream")
local server_class = require("snet.server")
local client_class = require("snet.client")
function snet.server(address, port)
local new_object = {}
setmetatable(new_object, {
__index = server_class,
__tostring = function()
return "SNET Server"
end
})
new_object.socket = socket.udp()
new_object.socket:settimeout(0)
new_object.socket:setsockname(address, port)
new_object.address = address
new_object.port = port
return new_object
end
function snet.client(address, port)
local new_object = {}
setmetatable(new_object, {
__index = client_class,
__tostring = function()
return "SNET Client"
end
})
new_object.socket = socket.udp()
new_object.socket:settimeout(0)
new_object.socket:setpeername(address, port)
new_object.address = address
new_object.port = port
return new_object
end
return snet |