I've written a java server application for a software solution I'm fiddling with.
The server uses multithreading to handle sockets and postgresql as a database. I'm worried about potential evil-doers, as right now, someone would easily be able to mess with my server by connecting repeatedly very fast.
Basically I'm looking for a way to only accept connections from computers, who haven't connected within the past second or w/e. I figured I could register all connecting and set a timer, but I also figured that the server could still be overloaded having to check many connections at the same time, albeit not as much as it would be without a timer.
I've searched stackoverflow and serverfault with no result to this specific problem :/.
The set up is really simple. All connections are accepted in the main method and forwarded to the corresponding thread:
public static void main(String[] args) {
gui = new mainFrame();
try {
ServerSocket serverSock = new ServerSocket(80);
while (true) {
Socket sock = serverSock.accept();
new Thread(new listenThread(sock)).start();
}
} catch (IOException ex) {
methods.log("Couldn't create server");
ex.printStackTrace();
}
}
Would appreciate any help. Mike.