Posted 18 June 2015 - 06:06 PM
So i've been working on a simple networking using the network cables in CC.
The idea is that i send a request to the "server"(aka main computer) and it would respond with and "accepted" message when the connection is allowed. I got that far.
The problem is that I want to set a max amount of connections to come in every x amount of seconds.
Example: I have my regular network running. Someone decides to decode the protocols my network uses and starts mass spamming my "server" how would i prevent it from accepting all those connections?
To say it very simple. Lets say i only want to allow 1 new connection at a time.
Code of the "server"
The idea is that i send a request to the "server"(aka main computer) and it would respond with and "accepted" message when the connection is allowed. I got that far.
The problem is that I want to set a max amount of connections to come in every x amount of seconds.
Example: I have my regular network running. Someone decides to decode the protocols my network uses and starts mass spamming my "server" how would i prevent it from accepting all those connections?
To say it very simple. Lets say i only want to allow 1 new connection at a time.
Code of the "server"
while true do
rednet.open("back")
local senderId, message, protocol = rednet.receive()
print("Log: ".."["..senderId.."] "..message)
rednet.send(senderId, "accepted")
print("Log: Established new connection."
end
code of the client
rednet.open("back")
print("Requesting connection...")
rednet.send(4, "Requesting connection...")
local senderId, message, protocol = rednet.receive(5)
if message == "Accepted" and senderId == 4 then
print("Connection established to server")
else
term.setTextColor(colors.red)
print("Connection timed out.")
term.setTextColor(colors.white)
end
And is the current code i use a efficient way or are there better methods?Edited on 18 June 2015 - 04:07 PM