How make ServerSocket only create Socket if connection from OK'd remote address?
posted 11 years ago
Looking at the code for ServerSocket, it appears that I can only reject or accept a connection (based on remote address) AFTER the socket has been created (via implAccept() ). But that means a ton of processing and object creation occurs for unallowed addresses. Is there a way to grab the remote address earlier in the process?
I really don't think that creating a socket instance only to reject it later is going to bring your computer to its knees. If it does, you may want to revisit your server hardware. If you are looking for a more efficient way to block certain IPs, how about using a firewall? They're designed to do that sort of thing without using a lot of resources and then your software would only have to deal with valid requests. The right tool for the job and all that.