updated files
This commit is contained in:
parent
97578e5073
commit
b98058f84e
48
client.lua
48
client.lua
@ -1,45 +1,11 @@
|
|||||||
package.path = "./?/init.lua;./?.lua;"..package.path
|
package.path = "./?/init.lua;./?.lua;"..package.path
|
||||||
-- local net = require("net.tcp")
|
local net = require("net.tcp")
|
||||||
-- local client = net:newTCPClient("localhost",12345)
|
|
||||||
|
|
||||||
-- client:send("Test!")
|
|
||||||
|
|
||||||
-- client.OnDataRecieved(function(c,data)
|
|
||||||
-- print("Response: ",data)
|
|
||||||
-- --c:send("Testing again!")
|
|
||||||
-- end)
|
|
||||||
|
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local https = require("net.https")
|
local client = net:newCastedClient("Test")--net:newTCPClient("localhost",12345)
|
||||||
|
|
||||||
-- multi:newThread("test1",function()
|
client:send("Test!")
|
||||||
-- local file = io.open("test1.jpg","wb")
|
|
||||||
-- data, code, headers, status = http.request("http://zjcdn.manga3fox.me/store/manga/33769/091.0/compressed/s20210705_163050_598.jpg")
|
|
||||||
-- print("Data:",data)
|
|
||||||
-- if headers then
|
|
||||||
-- for i,v in pairs(headers) do
|
|
||||||
-- print(i,v)
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- print(data,code,headers,status)
|
|
||||||
-- file:write(data)
|
|
||||||
-- file:flush()
|
|
||||||
-- file:close()
|
|
||||||
-- os.exit()
|
|
||||||
-- end).OnError(function(a,b,c)
|
|
||||||
-- print("Error: ",a,b,c)
|
|
||||||
-- --os.exit()
|
|
||||||
-- end)
|
|
||||||
|
|
||||||
data, code, headers, status = https.request("https://example.com/")
|
client.OnDataRecieved(function(c,data)
|
||||||
print(data, code, headers, status)
|
print("Response: ",data)
|
||||||
if headers then
|
end)
|
||||||
for i,v in pairs(headers) do
|
multi:mainloop()
|
||||||
print(i,v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- multi.OnExit(function()
|
|
||||||
-- print("Lua state being shutdown! :'(")
|
|
||||||
-- end)
|
|
||||||
-- multi:mainloop()
|
|
||||||
@ -49,6 +49,7 @@ function server:broadcast(name)
|
|||||||
bCaster = bCaster + 1
|
bCaster = bCaster + 1
|
||||||
self.isBroadcasting = true
|
self.isBroadcasting = true
|
||||||
self.process:newThread("Broadcast Handler<"..bCaster..">",function()
|
self.process:newThread("Broadcast Handler<"..bCaster..">",function()
|
||||||
|
print(table.concat({name,self.Type,self.localIP},"|")..":"..self.port)
|
||||||
while true do
|
while true do
|
||||||
thread.yield()
|
thread.yield()
|
||||||
self.broad:setoption("broadcast",true)
|
self.broad:setoption("broadcast",true)
|
||||||
@ -9,7 +9,7 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local ssl = require("ssl")
|
local ssl = require("ssl")
|
||||||
local ltn12 = require("ltn12")
|
local ltn12 = require("ltn12")
|
||||||
local http = require("net.http")
|
local http = require("net.http") -- Only real change that was needed to get things working
|
||||||
local url = require("socket.url")
|
local url = require("socket.url")
|
||||||
|
|
||||||
local try = socket.try
|
local try = socket.try
|
||||||
|
|||||||
11
net/init.lua
11
net/init.lua
@ -44,6 +44,7 @@ math.random()
|
|||||||
math.random()
|
math.random()
|
||||||
local multi, thread = require("multi").init()
|
local multi, thread = require("multi").init()
|
||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
|
local http = require("socket.http")
|
||||||
--ssl=require("ssl")
|
--ssl=require("ssl")
|
||||||
--https=require("ssl.https")
|
--https=require("ssl.https")
|
||||||
local net = {}
|
local net = {}
|
||||||
@ -98,7 +99,7 @@ function net.getLocalIP()
|
|||||||
return dat
|
return dat
|
||||||
end
|
end
|
||||||
function net.getExternalIP()
|
function net.getExternalIP()
|
||||||
local data = https.request("https://www.whatismypublicip.com/")
|
local data = http.request("http://www.myipnumber.com/my-ip-address.asp")
|
||||||
return data:match("(%d+%.%d+%.%d+%.%d+)")
|
return data:match("(%d+%.%d+%.%d+%.%d+)")
|
||||||
end
|
end
|
||||||
function net:registerModule(mod, version)
|
function net:registerModule(mod, version)
|
||||||
@ -153,11 +154,11 @@ function net:newCastedClient(name) -- connects to the broadcasted server
|
|||||||
local timer = multi:newTimer()
|
local timer = multi:newTimer()
|
||||||
while true do
|
while true do
|
||||||
local data, ip, port = listen:receivefrom()
|
local data, ip, port = listen:receivefrom()
|
||||||
if timer:Get() > 3 then
|
-- if timer:Get() > 3 then
|
||||||
error("Timeout! Server by the name: " .. name .. " has not been found!")
|
-- error("Timeout! Server by the name: " .. name .. " has not been found!")
|
||||||
end
|
-- end
|
||||||
if data then
|
if data then
|
||||||
--print("found!", data)
|
print("Found:", data)
|
||||||
local n, tp, ip, port = data:match("(%S-)|(%S-)|(%S-):(%d+)")
|
local n, tp, ip, port = data:match("(%S-)|(%S-)|(%S-):(%d+)")
|
||||||
if n:match(name) then
|
if n:match(name) then
|
||||||
--print("Found Server!", n, tp, ip, port)
|
--print("Found Server!", n, tp, ip, port)
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
local net = require("net")
|
local net = require("net")
|
||||||
local clientbase = require("net.clientbase")
|
local clientbase = require("net.core.clientbase")
|
||||||
local serverbase = require("net.serverbase")
|
local serverbase = require("net.core.serverbase")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local GLOBAL, THREAD = require("multi.integration.threading"):init()
|
|
||||||
local tcpcount = 0
|
local tcpcount = 0
|
||||||
function net:newTCPServer(port)
|
function net:newTCPServer(port)
|
||||||
local c = {}
|
local c = {}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
local net = require("net")
|
local net = require("net")
|
||||||
local clientbase = require("net.clientbase")
|
local clientbase = require("net.core.clientbase")
|
||||||
local serverbase = require("net.serverbase")
|
local serverbase = require("net.core.serverbase")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local GLOBAL, THREAD = require("multi.integration.threading"):init()
|
|
||||||
local CID = {}
|
local CID = {}
|
||||||
CID.__index = cid
|
CID.__index = cid
|
||||||
local udpcount = 0
|
local udpcount = 0
|
||||||
|
|||||||
@ -21,5 +21,11 @@ build = {
|
|||||||
type = "builtin",
|
type = "builtin",
|
||||||
modules = {
|
modules = {
|
||||||
["net.init"] = "net/init.lua",
|
["net.init"] = "net/init.lua",
|
||||||
|
["net.tcp.init] = "net/tcp/init.lua",
|
||||||
|
["net.udp.init] = "net/udp/init.lua",
|
||||||
|
["net.core.clientbase"] = "net/core/clientbase.lua"
|
||||||
|
["net.core.serverbase"] = "net/core/serverbase.lua"
|
||||||
|
["net.http"] = "net/http.lua"
|
||||||
|
["net.https"] = "net/https.lua"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
25
server.lua
25
server.lua
@ -1,14 +1,11 @@
|
|||||||
-- package.path = "./?/init.lua;./?.lua;"..package.path
|
package.path = "./?/init.lua;./?.lua;"..package.path
|
||||||
-- local net = require("net.tcp")
|
local net = require("net.tcp")
|
||||||
-- local server = net:newTCPServer(12345)
|
local multi, thread = require("multi"):init()
|
||||||
|
local server = net:newTCPServer(12345)
|
||||||
-- server.OnDataRecieved(function(serv, data,cid)
|
server:broadcast("Test")
|
||||||
-- print("Response: ",data)
|
print("Server has been broadcasted!")
|
||||||
-- server:send(cid,"Hello!")
|
server.OnDataRecieved(function(serv, data,cid)
|
||||||
-- end)
|
print("Response: ",data)
|
||||||
-- multi:mainloop()
|
server:send(cid,"Hello!")
|
||||||
http = require("socket.http")
|
end)
|
||||||
data, code, headers = http.request("http://zjcdn.mangafox.me/store/manga/33769/091.0/compressed/s20210705_163050_598.jpg")
|
multi:mainloop()
|
||||||
for i,v in pairs(headers) do
|
|
||||||
print(i,v)
|
|
||||||
end
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user