diff --git a/README.html b/README.html
new file mode 100644
index 0000000..bcd1469
--- /dev/null
+++ b/README.html
@@ -0,0 +1,184 @@
+
+
+
+
+ README.html
+
+
+
+
+
+
+net (2.0.1)
Updated from 2.0.0 to 2.0.1
Added:
+- Examples
- Support for latest multi version
- Updated readme
Discord
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries
https://discord.gg/U8UspuA
The net library was created to make servers and clients interact easily. This isn’t for webservers! (It could be, but you would need to code that part) The goal was to allow the creation for game servers!
This library depends on luasocket and you should use luajit! It will work on a standard lua interperter, but wont be as fast.
Goal
A simple and powerful way to make servers and clients
Todo
Note
You will see a bunch of files inside of the net folder. All that is stable is the init.lua and sft.lua file. Everything else is a work in progress. Plus I am planning on rewritting all of the modules to take advantage of the new threading features that are found in the new multi updates. PRogress on this will be made soon. I have just been away from my PC for a while.
Usage
server.lua
require("bin")
+require("multi")
+require("net")
+server=net:newTCPServer(12345)
+server.OnDataRecieved(function(self,data,CID_OR_HANDLE,IP_OR_HANDLE,PORT_OR_IP,UPDATER_OR_NIL)
+ if data=="Hello!" then
+ print("Got response from client sending back data!")
+ self:send(IP_OR_HANDLE,"Hello Client!",PORT_OR_IP)
+ end
+end)
+multi:mainloop()
+
client.lua
require("bin")
+require("multi")
+require("net")
+client=net:newTCPClient("localhost",12345)
+client.OnClientReady(function(self)
+ self:send("Hello!")
+end)
+client.OnDataRecieved(function(self,data)
+ if data=="Hello Client!" then
+ print("Server Responded Back!")
+ end
+end)
+multi:mainloop()
+
There is support for broadcasting, multicasting will be added soon requires luasocker 3.0+.
Here is a broadcasting example:
broadcastingExampleServer.lua (included in example folders)
package.path="?/init.lua;"..package.path
+
+
+require("bin")
+require("multi")
+require("net")
+server=net:newServer(12345)
+server.OnDataRecieved(function(self,data,CID_OR_HANDLE,IP_OR_HANDLE,PORT_OR_IP,UPDATER_OR_NIL)
+ if data=="Hello!" then
+ print("Got response from client sending back data!")
+ self:send(IP_OR_HANDLE,"Hello Client!",PORT_OR_IP)
+ end
+end)
+server:broadcast("Lua_Server")
+multi:mainloop()
+
broadcastingExampleClient.lua (included in example folders)
package.path="?/init.lua;"..package.path
+require("bin")
+require("multi")
+require("net.aft")
+client=net:newCastedClient("Lua_Server")
+
+client.OnClientReady(function(self)
+ self:send("Hello!")
+end)
+client.OnDataRecieved(function(self,data)
+ if data=="Hello Client!" then
+ print("Server Responded Back!")
+ end
+end)
+multi:mainloop()
+
The net library also provides a powerful module creation interface. You have all of the modules in the net folder as examples, however I will show you how you could go about creating your own!
All functions include:
+- net.OnServerCreated() — Refer to the multi library example on connections: https://github.com/rayaman/multi#connections
- net.OnClientCreated() — ^^
- net.normalize(input) — formats data in base 64
- net.denormalize(input) — takes base 64 data and turns it back into what it was
- net.getLocalIP() — returns your loacl ip
- net.getExternalIP() — If this ever stops working let me know… Ill have to update the service I am using
- net:registerModule(mod,version) — registers a module. Checks out the example below
- net.getModuleVersion(ext) — returns the version of a module
- net.resolveID(obj) — an internal method for generating unique IDs obj is a table with an ID key
- net.inList(list,dat) — checks if dat is a value in list
- net.setTrigger(funcW,funcE) — Currently does nothing… I forgot where I was going with this
- net:newCastedClient(name) — connects to a server that is being broadcasted see above example
- net:newServer(port,servercode) — creates a UDP Server
- net:newClient(host,port,servercode,nonluaServer) — creates a UDP Client
- net:newTCPServer(port) — creates a TCP Server
- net:newTCPClient(host,port) — creates a TCP Client
Both TCP/UPD Clients and Servers contain the same methods:
Server Object:
General Server Methods
+- serverobj:setUpdateRate(n)
- server:banCID(cid)
- server:banIP(ip)
- server:broadcast(name)
- server:send(ip,data,port,cid)
- server:pollClientModules(ip,port)
- server:CIDFrom(ip,port)
- server:sendAll(data)
- server:sendAllBut(data,cid)
- server:clientRegistered(cid)
- server:clientLoggedIn(cid)
- server:update() — Internal method do not call!
- server.OnClientsModulesList()
- server.OnDataRecieved()
- server.OnClientClosed()
- server.OnClientConnected()
- server.hostip=net.getLocalIP()
- server.port
TCP Server Only Methods
+- server:setReceiveMode(mode)
- server:setSendMode(mode)
- server:sendAllData(handle,data)
- server:getUpdater(cid)
General Client Methods
+- client:send(data)
- client:sendRaw(data)
- client:close()
- client:getCID()
- client:update() — Internal method do not call!
- client:reconnect()
- client:IDAssigned()
- client.OnDataRecieved()
- client.OnClientReady()
- client.OnClientDisconnected()
- client.OnConnectionRegained()
UDP Client Only Methods
+- client.OnPingRecieved()
- client.OnServerNotAvailable
TCP Client Only Methods
+- client:setReceiveMode(mode)
- client:setSendMode(mode)
When using the module creation support here is the shell that you can use:
require("net")
+local MODULENAME="EXAMPLE"
+net:registerModule(MODULENAME,{1,0,0})
+if not io.dirExists(string.upper(MODULENAME)) then
+ io.mkDir(string.upper(MODULENAME))
+end
+net.OnServerCreated:connect(function(s)
+ s.OnDataRecieved(function(self,data,CID_OR_HANDLE,IP_OR_HANDLE,PORT_OR_IP)
+ local cmd,arg1,arg2=data:match("!"..MODULENAME.."! (%S+) (%S+) (%S+)")
+ if cmd=="SEND" then
+
+ elseif cmd=="GET" then
+
+ end
+ end,MODULENAME)
+end)
+net.OnClientCreated:connect(function(c)
+ c.OnDataRecieved(function(self,data)
+ local cmd,arg1,arg2=data:match("!"..MODULENAME.."! (%S+) (%S+) (%S+)")
+ if cmd=="SEND" then
+
+ elseif cmd=="GET" then
+
+ end
+ end,MODULENAME)
+end)
+
The bin and multi library can be found on my github page. They are all ‘100%’(If you ingore intergrations) pure lua so it should be easy to add to your project.
https://github.com/rayaman/multi
https://github.com/rayaman/bin
+
+
+
+
diff --git a/README.md b/README.md
index 1b760ae..c6ad1f9 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,8 @@ A simple and powerful way to make servers and clients
- [ ] Threading - Simple threading ~~(UDP/AUDP Only)~~ Thanks to an updated multi library we can thread with ease
- [ ] Priority handling
+# Note
+You will see a bunch of files inside of the net folder. All that is stable is the init.lua and sft.lua file. Everything else is a work in progress. Plus I am planning on rewritting all of the modules to take advantage of the new threading features that are found in the new multi updates. PRogress on this will be made soon. I have just been away from my PC for a while.
# Usage
server.lua
```lua
diff --git a/net/emailWIP.lua b/net/emailWIP.lua
deleted file mode 100644
index dbea43a..0000000
--- a/net/emailWIP.lua
+++ /dev/null
@@ -1,53 +0,0 @@
-require("net.identity")
-net:registerModule("email",{1,0,0})
-smtp = require 'socket.smtp'
-ssl = require 'ssl'
-
-function net.email.init(from,user,pass)
- net.OnServerCreated:connect(function(s)
- s.from=from
- s.user=user
- s.pass=pass
- function s:sendMessage(subject, body, dTable)
- local msg = {
- headers = {
- from = '<'..dTable.email..'>'
- to = dTable.nick..' <'..dTable.email..'>',
- subject = subject
- },
- body = body
- }
- local ok, err = smtp.send {
- from = '<'..self.from..'>',
- rcpt = '<'..dTable.email..'>',
- source = smtp.message(msg),
- user = self.user,
- password = self.pass,
- server = 'smtp.gmail.com',
- port = 465,
- create = net.sslCreate
- }
- if not ok then
- print("Mail send failed", err) -- better error handling required
- end
- end
- end)
-end
-function net.sslCreate()
- local sock = socket.tcp()
- return setmetatable({
- connect = function(_, host, port)
- local r, e = sock:connect(host, port)
- if not r then return r, e end
- sock = ssl.wrap(sock, {mode='client', protocol='tlsv1'})
- return sock:dohandshake()
- end
- }, {
- __index = function(t,n)
- return function(_, ...)
- return sock[n](sock, ...)
- end
- end
- })
-end
-
diff --git a/net/loggingWIP.lua b/net/loggingWIP.lua
deleted file mode 100644
index be82728..0000000
--- a/net/loggingWIP.lua
+++ /dev/null
@@ -1,7 +0,0 @@
-net.OnServerCreated:connect(function(s)
- print("The logging Module has been loaded onto the server!")
- s.OnDataRecieved:fConnect(function(self,data,cid,ip,port)
- log(tostring(ip)..":"..tostring(port),"Server-log.log")
- log(data,"Server-log.log")
- end)
-end)
diff --git a/net/p2pWIP.lua b/net/p2pWIP.lua
deleted file mode 100644
index a1ece36..0000000
--- a/net/p2pWIP.lua
+++ /dev/null
@@ -1,31 +0,0 @@
-net:registerModule("p2p",{1,0,0})
-net.p2p.peerdata={}
---[[
-PID(peerID)=
-
-]]
-function net.newP2PClient(host,port)
- --
-end
-function net.aft:init() -- calling this initilizes the library and binds it to the servers and clients created
- --Server Stuff
- net.OnServerCreated:connect(function(s)
- print("The aft(Advance File Transfer) Module has been loaded onto the server!")
- if s.Type~="udp" then
- print("As of right now p2p is only avaliable using udp!")
- return "ERR_NOT_UDP"
- end
- s.OnDataRecieved(function(self,data,cid,ip,port) -- when the server recieves data this method is triggered
- --
- end,"p2p") -- some new stuff
- end)
- --Client Stuff
- net.OnClientCreated:connect(function(c)
- c.OnDataRecieved(function(self,data) -- when the client recieves data this method is triggered
- --
- end,"p2p")
- end)
-end
-if net.autoInit then
- net.aft.init()
-end
diff --git a/net/settingsWIP.lua b/net/settingsWIP.lua
deleted file mode 100644
index de9c190..0000000
--- a/net/settingsWIP.lua
+++ /dev/null
@@ -1,48 +0,0 @@
-require("net")
---General Stuff
---[[ What this module does!
-Adds
-net.settings:init()
-server:regSetting(namespace,setting)
-]]
-net:registerModule("settings",{1,0,0})
-net.settings.config={}
-function net.settings:init() -- calling this initilizes the library and binds it to the servers and clients created
- --Server Stuff
- net.OnServerCreated:connect(function(s)
- print("The Settings Module has been loaded onto the server!")
- s.OnDataRecieved(function(self,data,cid,ip,port) -- when the server recieves data this method is triggered
- local namespace,args=data:match("!settings! (%s+) (.+)")
- local args
- if namespace then
- for i,v in pairs(net.settings.config) do
- args={data:match(v[1])}
- if #args~=0 then
- v[2]:Fire(self,data,cid,ip,port,unpack(args))
- break
- end
- end
- end
- end,"settings")
- function s:regSetting(namespace,settings)
- if not net.settings.config[namespace] then
- net.settings.config[namespace]={}
- end
- local connection=multi:newConnection()
- table.insert(net.settings.config[namespace],{"!settings! "..namespace.." "..settings,connection})
- return connection
- end
- end)
- --Client Stuff
- net.OnClientCreated:connect(function(c)
- c.OnDataRecieved:(function(self,data) -- when the client recieves data this method is triggered
- --First Lets make sure we are getting Setting data
- end,"setings")
- function sendSetting(namespace,args)
- self:send("!settings! "..namespace.." "..args)
- end
- end)
-end
-if net.autoInit then
- net.settings:init()
-end
diff --git a/net/threadingWIP.lua b/net/threadingWIP.lua
deleted file mode 100644
index c83b2c2..0000000
--- a/net/threadingWIP.lua
+++ /dev/null
@@ -1,37 +0,0 @@
---[=[ About This Module!
- This module is server side only! (Might add client side if requested)
- Aim is to make each lane (thread) have no more than 'n' number of connections
- This module hyjacks the multi:newConnection() function to seemlessly add support for threads without you having to change much
- As long as each server-client connection is isolated you should be fine
- The chatting module however IS NOT an isolated module, so take a look at how data was handled in that module to allow for both
- threaded and non threaded use
-
- How?
- When this module is loaded all server creation is altered by passing a proxyServer instead of an actual server object
- for example:
- proxy=net:newTCPServer(12345)
- proxy:OnDataRecieved(function(self,data,cid,ip,port)
- self:send("My data!")
- end)
- the real server instance could be on any of the threads. Careful! While using this is seemless becareful of IO opperations!
-]=]
---~ net:registerModule("threading",{1,0,0})
---~ if not(lanes) then error("Require the lanes module!") end
---~ local serverlinda = lanes.linda()
---~ net.threading.newServer=net.newServer -- store the original method
---~ net.threading.newTCPServer=net.newTCPServer -- store the original method
---~ net.threading.proxy={} -- namespace for the proxy stuff. Because of the desgin intention of both UDP/TCP servers Only one proxy is needed
-lanes=require("lanes")
-serverlinda = lanes.linda()
-mt={
- __index=function(t,k) print("IND",t,k) end,
- __newindex=function(t,k,v) print("NewIND",t,k,v) end,
-}
-test={}
-setmetatable(test,mt)
-test.a="hi"
-test.a=true
-g=test['a']
-print(test.b)
---~ setmetatable(net.threading.proxy,mt) -- set the proxies metatable, to prevent bleeding only create one server.
-