Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

SocketException: Connection reset

Thread view: 
bigBrother82 - 05 Nov 2005 05:07 GMT
I am currently trying to write a simple ftp client. I have only
recently started and I am running into a problem. Obviously I have not
coded everything yet. I am trying to connect to a remote ftp server,
but not to the login state yet. This is the error I receive:

SocketException: Connection reset
 at java.net.SocketInputStream.read(Unknown Source)
 at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(Unknown Source)
 at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
 at sun.nio.cs.StreamDecoder.read(Unknown Source)
 at java.io.InputStreamReader.read(Unknown Source)
 at java.io.BufferedReader.fill(Unknown Source)
 at java.io.BufferedReader.readLine(Unknown Source)
 at java.io.BufferedReader.readLine(Unknown Source)
 at csci4311.ftp.FTPcommands.serverReply(FTPcommands.java:78)
 at csci4311.ftp.FTPcommands.successful(FTPcommands.java:67)
 at csci4311.ftp.FTPcommands.connect(FTPcommands.java:27)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)

The problem is coming from my inputStream. I am using a BufferedReader
as the input stream. It appears that the error is being sparked when I
envoke the bufferedreader method readLine(). Here is my code:

package ftp;

import java.io.*;
import java.net.*;
import java.util.*;

public class FTPcommands{

 private Socket socketConnection = null; //the socket we are conected
to the ftp server
 private PrintStream outputStream = null;//the socket outputstream
 private BufferedReader inputStream = null;//the socket inputstream
 private boolean connected;

 public FTPcommands(){
   this.connected = false;
 }

 public void connect(String host, int port) throws
UnknownHostException, IOException{
   this.socketConnection = new Socket(host, port);
   this.outputStream = new
PrintStream(socketConnection.getOutputStream());
   this.inputStream = new BufferedReader(new
InputStreamReader(socketConnection.getInputStream()));
   if (!successful())
     disconnect();
   else
     this.connected = true;
 }

 public void disconnect(){
   {
     if (this.outputStream != null) {
       try {
         if (this.connected)
           logout();
         this.outputStream.close();
         this.inputStream.close();
         this.socketConnection.close();
       } catch (IOException e) {}

       this.outputStream = null;
       this.inputStream = null;
       this.socketConnection = null;
     }
   }
 }

 public void logout() throws IOException{
   int response = executeCommand("quit");
   this.connected = !successful();
 }

 public int executeCommand(String command) throws IOException{
   this.outputStream.println(command);
   return serverReply();
 }

 public boolean isConnected(){
   return this.connected;
 }

 public boolean successful() throws IOException{
   boolean successful;
   int code = serverReply();
   if (code >= 200 && code < 300)
     successful = true;
   else
     successful = false;
   return successful;
 }

 public int serverReply() throws IOException{
   String serverReply;
   do {
     serverReply = this.inputStream.readLine();
   } while(!(Character.isDigit(serverReply.charAt(0)) &&
             Character.isDigit(serverReply.charAt(1)) &&
             Character.isDigit(serverReply.charAt(2)) &&
             serverReply.charAt(3) == ' '));

   return Integer.parseInt(serverReply.substring(0, 3));
 }

}//end class FTPcommands.java

The readLine() method is invoked in serverReply() above.

I am stumped, and have searched google vigarously for severel days now
lookin for answers or suggestions. Any insight at all would be greatly
appreciated.

Sincerely,
Jacob Schoen
Roedy Green - 05 Nov 2005 09:48 GMT
>SocketException: Connection reset
>  at java.net.SocketInputStream.read(Unknown Source)
[quoted text clipped - 12 lines]
>  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>  at java.lang.reflect.Method.invoke(Unknown Source)

you are not getting any line numbers.  Try using the Java.exe that
comes with the JDK not the JRE. Perhaps that will help you narrow it
down.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.