• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation of server host string

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was reviewing my code and noticed that I didn't include much validation on the server host string in my configuration dialog.

I decided the user was free to use anything (to allow host name instead of using IP).

But even if I just allow IP address, any valid IP is considered, thus when I attempt to connect to www.google.com, for instance, the application hangs in my lookup call.

How can I get around this?

Thanks in advance.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Batista -

Are you using sockets or rmi?
On RMI I can comment:

The application doesn't hang. You get a . But it takes some time (around 1 min maybe which is adjustable.)

Usually you do something like this to get the remote object:


But when you try with google:

it appears to be hanged... but you get a after a while.

java.rmi.ConnectException: Connection refused to host: www.google.com; nested exception is:
java.net.ConnectException: Connection timed out: connect



Even with proper RMI Server there maybe a time lag if it's a remote machine and network traffic is high.

So I think you should change the mouse cursor to Hour-Glass informing the user that we are waiting for the server to respond and change it back when we get a response or exception.
 
k kris
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops. Sorry there. I thought [CODE] works like <code> in HTML
I didn't know it was <p><hr><code>...</hr></code></p>
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

For server host, I suggest you should validate it by using java.net.InetAddress class. This class can check both IP address and host name.

Hope this help.
 
Jo�o Batista
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for the replies!
This forum rocks!
reply
    Bookmark Topic Watch Topic
  • New Topic