How to validate IP and Port

Hi allI am trying to connect RFID devices. For this I am sending IP and Port to the devices from JSP page but some time if user doent enter the correct IP and Port, So I wanna validate it. Is there anyway to validate it?Thanxkvijai
[259 byte] By [kvijaia] at [2007-11-26 15:34:59]
# 1
What kind of validation are you talking about? Syntax? Functionality? What are your validation rules?
CeciNEstPasUnProgrammeura at 2007-7-8 21:52:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi

I am sending IP and Port as a String to external device(RFID Reader) to connect it.

(1) Suppose

IP: 192.168.0.3 or 192.168.200.5

Port: 2189

If user put IP and Port not in the standard format of IP and Port then it alert about it.

(2) IF POSSIBLE, that we can scan the IP and Port of the connected devices that should be really very good.

Thanx

kvijai

kvijaia at 2007-7-8 21:52:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

>(1) Suppose

>IP: 192.168.0.3 or 192.168.200.5

>Port: 2189

>If user put IP and Port not in the standard format of IP and Port then it >alert about it.

this could be manged by client side validations using javascript

checkout the link below which gives you a code snippet to validate by considering standard format

http://javascript.internet.com/forms/val-ip.html?IPvalue=1233.233.22.3

and coming about application port validation which could fall in the range of 0 to 65535 where Registered,Dynamic & Private Ports fall in the range of 1024 to 65535.You can write a snippet accordingly.

or make use of the snippet specified below.

function appValidation(txt){

if(isNaN(txt) == false){

if(txt >=1024 && txt<=65535)

return(true);

}

return(false);

}

>(2) IF POSSIBLE, that we can scan the IP and Port of the connected >devices that should be really very good.

Well this has to be made @ the server side where you may actually program a Customized exception class by which be return certain results if @ all you wanna check everything in same form under same view source make use of AJAX else where you can pretty well use it after form submission to the respective servlet/JSP.

REGARDS,

RaHuL

RahulSharnaa at 2007-7-8 21:52:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Thanx Rahul

Actually I am using two fields one for IP and another for Port and there is one button CONNECT if I click this CONNECT button it posts to another JSP page which connects to RFID Reader. Now my problem is that how to manage these two javascript functions [ function verifyIP (IPvalue) & function appValidation(txt)] with one CONNECT button to validate IP and Port before sending to another JSP page.

Thanx

kvijai

kvijaia at 2007-7-8 21:52:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

write an action to connect button(using type="button" not type="submit")

say something like the one below

...

......

..........

<script language>

function formSubmit(){

var flag = 0

if( verifyIP(document.RfidForm.ipaddress.value) = false){

alert("Invalid IPADRESS entered");

flag = 1;

}

if(appValidation(document.RfidForm.appport.value) == false){

alert(""Invalid APPLICATION PORT # entered"");

flag = 1;

}

if(flag = = 0){

// Form Action

document.RfidForm.action = "RfidServlet ";

// Form method

document.RfidForm.method = "POST";

document.RfidForm.submit();

}

}

...

......

..........

...

......

..........

...

......

..........

</script>

...

......

..........

<form name="RfidForm">

<input name="ipaddress" type="text">

<input name="appport" type="text">

<input name="submit" type="button" onlclick="formSubmit()" value="CONNECT">

</form>

...

......

..........

...

......

..........

Hope this example snippet have given some idea to you.

REGARDS,

RaHuL

RahulSharnaa at 2007-7-8 21:52:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...