• Post Reply Bookmark Topic Watch Topic
  • New Topic

Validation of server host string

 
Jo�o Batista
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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.
 
k kris
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
  • 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>
 
Soroj Margun
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Many thanks for the replies!
This forum rocks!
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!