Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How make ServerSocket only create Socket if connection from OK'd remote address?  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Joe Ess
Bartender
Posts: 9436
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!