Skip site navigation (1)Skip section navigation (2)
Date:      06 Aug 2003 18:11:37 -0400
From:      "Michael E. Mercer" <mmercer@nc.rr.com>
To:        "Lapinski, Michael (Research)" <lapinski@crd.ge.com>
Cc:        freebsd-java@freebsd.org
Subject:   RE: Socket Exception using 1.4
Message-ID:  <1060207897.13023.13.camel@dual.mmercer.com>
In-Reply-To: <E4AAC34FE3CF564D8AE89EB8AC333FD709165219@xmb03crdge.crd.ge.com>
References:  <E4AAC34FE3CF564D8AE89EB8AC333FD709165219@xmb03crdge.crd.ge.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--=-aqumX4pxvqAGS3m5zreH
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

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@nc.rr.com] 
> Sent: Wednesday, August 06, 2003 3:08 PM
> To: freebsd-java@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@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-java
> To unsubscribe, send any mail to "freebsd-java-unsubscribe@freebsd.org"

--=-aqumX4pxvqAGS3m5zreH--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1060207897.13023.13.camel>