aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes ServerSocket deny connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "ServerSocket deny connection" Watch "ServerSocket deny connection" New topic
Author

ServerSocket deny connection

Doua Beri
Ranch Hand

Joined: Sep 24, 2009
Posts: 60
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 Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Doua Beri
Ranch Hand

Joined: Sep 24, 2009
Posts: 60
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 Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Not in Java. You can configure your firewall to block all connections from that host, but you can't do that from Java.
Doua Beri
Ranch Hand

Joined: Sep 24, 2009
Posts: 60
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServerSocket deny connection