Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

ServerSocket deny connection

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22647
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Doua Beri
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22647
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic