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
|
||||
-- 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 net = require("net.tcp")
|
||||
local multi, thread = require("multi"):init()
|
||||
local https = require("net.https")
|
||||
local client = net:newCastedClient("Test")--net:newTCPClient("localhost",12345)
|
||||
|
||||
-- multi:newThread("test1",function()
|
||||
-- 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)
|
||||
client:send("Test!")
|
||||
|
||||
data, code, headers, status = https.request("https://example.com/")
|
||||
print(data, code, headers, status)
|
||||
if headers then
|
||||
for i,v in pairs(headers) do
|
||||
print(i,v)
|
||||
end
|
||||
end
|
||||
|
||||
-- multi.OnExit(function()
|
||||
-- print("Lua state being shutdown! :'(")
|
||||
-- end)
|
||||
-- multi:mainloop()
|
||||
client.OnDataRecieved(function(c,data)
|
||||
print("Response: ",data)
|
||||
end)
|
||||
multi:mainloop()
|
||||
@ -49,6 +49,7 @@ function server:broadcast(name)
|
||||
bCaster = bCaster + 1
|
||||
self.isBroadcasting = true
|
||||
self.process:newThread("Broadcast Handler<"..bCaster..">",function()
|
||||
print(table.concat({name,self.Type,self.localIP},"|")..":"..self.port)
|
||||
while true do
|
||||
thread.yield()
|
||||
self.broad:setoption("broadcast",true)
|
||||
@ -9,7 +9,7 @@
|
||||
local socket = require("socket")
|
||||
local ssl = require("ssl")
|
||||
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 try = socket.try
|
||||
|
||||
11
net/init.lua
11
net/init.lua
@ -44,6 +44,7 @@ math.random()
|
||||
math.random()
|
||||
local multi, thread = require("multi").init()
|
||||
local socket = require("socket")
|
||||
local http = require("socket.http")
|
||||
--ssl=require("ssl")
|
||||
--https=require("ssl.https")
|
||||
local net = {}
|
||||
@ -98,7 +99,7 @@ function net.getLocalIP()
|
||||
return dat
|
||||
end
|
||||
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+)")
|
||||
end
|
||||
function net:registerModule(mod, version)
|
||||
@ -153,11 +154,11 @@ function net:newCastedClient(name) -- connects to the broadcasted server
|
||||
local timer = multi:newTimer()
|
||||
while true do
|
||||
local data, ip, port = listen:receivefrom()
|
||||
if timer:Get() > 3 then
|
||||
error("Timeout! Server by the name: " .. name .. " has not been found!")
|
||||
end
|
||||
-- if timer:Get() > 3 then
|
||||
-- error("Timeout! Server by the name: " .. name .. " has not been found!")
|
||||
-- end
|
||||
if data then
|
||||
--print("found!", data)
|
||||
print("Found:", data)
|
||||
local n, tp, ip, port = data:match("(%S-)|(%S-)|(%S-):(%d+)")
|
||||
if n:match(name) then
|
||||
--print("Found Server!", n, tp, ip, port)
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
local net = require("net")
|
||||
local clientbase = require("net.clientbase")
|
||||
local serverbase = require("net.serverbase")
|
||||
local clientbase = require("net.core.clientbase")
|
||||
local serverbase = require("net.core.serverbase")
|
||||
local multi, thread = require("multi"):init()
|
||||
local GLOBAL, THREAD = require("multi.integration.threading"):init()
|
||||
local tcpcount = 0
|
||||
function net:newTCPServer(port)
|
||||
local c = {}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
local net = require("net")
|
||||
local clientbase = require("net.clientbase")
|
||||
local serverbase = require("net.serverbase")
|
||||
local clientbase = require("net.core.clientbase")
|
||||
local serverbase = require("net.core.serverbase")
|
||||
local multi, thread = require("multi"):init()
|
||||
local GLOBAL, THREAD = require("multi.integration.threading"):init()
|
||||
local CID = {}
|
||||
CID.__index = cid
|
||||
local udpcount = 0
|
||||
|
||||
@ -21,5 +21,11 @@ build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
["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
|
||||
-- local net = require("net.tcp")
|
||||
-- local server = net:newTCPServer(12345)
|
||||
|
||||
-- server.OnDataRecieved(function(serv, data,cid)
|
||||
-- print("Response: ",data)
|
||||
-- server:send(cid,"Hello!")
|
||||
-- end)
|
||||
-- multi:mainloop()
|
||||
http = require("socket.http")
|
||||
data, code, headers = http.request("http://zjcdn.mangafox.me/store/manga/33769/091.0/compressed/s20210705_163050_598.jpg")
|
||||
for i,v in pairs(headers) do
|
||||
print(i,v)
|
||||
end
|
||||
package.path = "./?/init.lua;./?.lua;"..package.path
|
||||
local net = require("net.tcp")
|
||||
local multi, thread = require("multi"):init()
|
||||
local server = net:newTCPServer(12345)
|
||||
server:broadcast("Test")
|
||||
print("Server has been broadcasted!")
|
||||
server.OnDataRecieved(function(serv, data,cid)
|
||||
print("Response: ",data)
|
||||
server:send(cid,"Hello!")
|
||||
end)
|
||||
multi:mainloop()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user