Socket Exception using 1.4
Michael E. Mercer
mmercer at nc.rr.com
Wed Aug 6 15:11:44 PDT 2003
Attached you will find LRC.java... LRC=Linksys Router Connection
This code when run by version 1.3 works fine.
When run by 1.4, it throws a SocketException.
Here is the code inline... it throws the exception at the readLine()
call.
to run it, the params are <username> <password> <IP> <page>
<username> username of the Linksys Router
<password> password for Linksys Router
<IP> IP address assigned to the Linksys Router
<page> the page you want to retrieve
Thanks
MeM
/*
* Created on Aug 6, 2003
*/
package com.mmercer.lrc;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
/**
* @author mmercer
*/
public class LRC
{
/**
*
*/
public LRC()
{
super();
}
public String retrievePage(String host, String page)
{
StringBuffer result = new StringBuffer();
URL url = null;
try
{
// do stuff here.
url = new URL("http", host, 80, "/" + page);
// System.out.println( url.toString() );
URLConnection conn = url.openConnection();
// update headers here...
conn.connect();
InputStreamReader isr =
new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(isr);
String line = null;
while (br.ready() && ((line = br.readLine()) != null))
{
result.append(line).append("\n");
}
}
catch (Exception e)
{
e.printStackTrace();
}
return result.toString();
}
public static void main(String[] args)
{
if (args.length != 4)
{
System.err.println(
"usage: java LRC <username> <password> <host> <page>");
System.exit(1);
}
LRC lrc = new LRC();
Authenticator.setDefault(lrc.new MyAuthenticator(args[0],
args[1]));
String result = lrc.retrievePage(args[2], args[3]);
if (null == result)
return;
System.out.println(result);
}
class MyAuthenticator extends Authenticator
{
private PasswordAuthentication pw;
MyAuthenticator(String username, String password)
{
pw = new PasswordAuthentication(username,
password.toCharArray());
}
protected PasswordAuthentication getPasswordAuthentication()
{
return pw;
}
}
}
On Wed, 2003-08-06 at 15:21, Lapinski, Michael (Research) wrote:
> One suggestion, try using NetworkInterface
> to poll for up/down/ip info (I read a short
> Article in the java developers journal about
> it and would be willign to fax it to you or
> Something).
>
> Second, the first thing that comes to mind
> is policy files for the JVM, ive seen a lot
> of weird socket excpetions with RMI stuff
> that ended up being policy issues.
>
> If that doesn't do anything send a code
> snippet and maybe I can be of help.
>
>
> -mtl
>
> --------------------------------------------------
> Michael Lapinski
> Computer Scientist
> GE Research
>
> -----Original Message-----
> From: Michael E. Mercer [mailto:mmercer at nc.rr.com]
> Sent: Wednesday, August 06, 2003 3:08 PM
> To: freebsd-java at freebsd.org
> Subject: Socket Exception using 1.4
>
>
> Hello,
>
> I have a Linksys Router that I access via a java program to get my current
> IP.
>
> I use my own Authenticator and use URL to get a URLConnection.
>
> When I use 1.3, everything works just fine.
>
> However using 1.4 throws a "Socket Reset" SocketException everytime.
>
> If you need me to write a sample code snippet to explain what exactly I'm
> doing, then I will.
>
> Thanks
> Michael Mercer
>
> _______________________________________________
> freebsd-java at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-java
> To unsubscribe, send any mail to "freebsd-java-unsubscribe at freebsd.org"
More information about the freebsd-java
mailing list