Hi. I have a ServerSocket and I accept connection using the accept() method. However I want to deny the connection if the request comes from a certain IP. I have searched but didn't find any related method. Can you help me? Thanks in advance
Rob Prime wrote:After accepting check out the Socket's remote address (check out java.net.Socket), and close the socket if you don't want the connection.
Thanks for the quick reply. So basically I need accept the connection and then make the verification and after that I close the socket. There is no other way without accepting the connection?
Rob Prime wrote:Not in Java. You can configure your firewall to block all connections from that host, but you can't do that from Java.
Yes. I searched a lot in the last hour and didn't find any solution. However on the implAccept(socket); which can be override there is the following code
I'm not sure if this is a solution and I looked for an example of using SecurityManager or SocketPermission but without any luck.
Evildoers! Eat my justice! And this tiny ad's justice too!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth