IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Entrée/Sortie Java Discussion :

java.net.SocketException: Connection reset


Sujet :

Entrée/Sortie Java

  1. #1
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    251
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 251
    Par défaut java.net.SocketException: Connection reset
    Bonjour,

    Je sais que ce type de post a été très souvent mis. Mais là j'y arrive pas du tout.

    J'ai une appli qui tourne en europe et qui fait des transfert ftp sur un server payant. tout ce passe bien. La même application au mexique un fait aucun transfert. L'erreur qui sort est la suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    java.net.SocketException: Connection reset
            at java.net.SocketInputStream.read(SocketInputStream.java:168)
            at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:411)
            at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:453)
            at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:183)
            at java.io.InputStreamReader.read(InputStreamReader.java:167)
            at java.io.BufferedReader.fill(BufferedReader.java:136)
            at java.io.BufferedReader.readLine(BufferedReader.java:299)
            at java.io.BufferedReader.readLine(BufferedReader.java:362)
            at FTPConnection.getFullServerReply(FTPConnection.java:451)
            at FTPConnection.getServerReply(FTPConnection.java:436)
            at FTPConnection.openPort(FTPConnection.java:918)
            at FTPConnection.setupDataPort(FTPConnection.java:855)
            at FTPConnection.executeDataCommand(FTPConnection.java:769)
            at FTPConnection.writeDataFromFile(FTPConnection.java:710)
            at FTPConnection.uploadFile(FTPConnection.java:399)
            at FTPConnection.main(FTPConnection.java:1014)
    voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    private String getFullServerReply()
            throws IOException
        {
            String reply;
     
            do {
                reply = inputStream.readLine();
                debugPrint(reply);
            } while(!(Character.isDigit(reply.charAt(0)) && 
                      Character.isDigit(reply.charAt(1)) &&
                      Character.isDigit(reply.charAt(2)) &&
                      reply.charAt(3) == ' '));
     
            return reply;
        }
     
     private int getServerReply()
            throws IOException
        {
            return Integer.parseInt(getFullServerReply().substring(0, 3));
        }
     
    private boolean openPort(ServerSocket serverSocket)
            throws IOException
        {                        
            int localport = serverSocket.getLocalPort();
     
            // get local ip address
            InetAddress inetaddress = serverSocket.getInetAddress();
            InetAddress localip;
            try {
                localip = inetaddress.getLocalHost();
            } catch(UnknownHostException e) {
                debugPrint("Can't get local host");
                return false;
            }
     
            // get ip address in high byte order
            byte[] addrbytes = localip.getAddress();
     
            // tell server what port we are listening on
            short addrshorts[] = new short[4];
     
            // problem:  bytes greater than 127 are printed as negative numbers
            for(int i = 0; i <= 3; i++) {
                addrshorts[i] = addrbytes[i];
                if (addrshorts[i] < 0)
                    addrshorts[i] += 256;
            }
     
            outputStream.println("port " + addrshorts[0] + "," + addrshorts[1] +
                                 "," + addrshorts[2] + "," + addrshorts[3] + "," +
                                 ((localport & 0xff00) >> 8) + "," +
                                 (localport & 0x00ff));
     
            return isPositiveCompleteResponse(getServerReply());
        }
     
    private boolean setupDataPort(String command, ServerSocket serverSocket)
            throws IOException
        {
            // Send our local data port to the server
            if (!openPort(serverSocket)) return false;
     
            // Set binary type transfer
            outputStream.println("type i");
            if (!isPositiveCompleteResponse(getServerReply())) {
                debugPrint("Could not set transfer type");
                return false;
            }
     
            // If we have a restart point, send that information
            if (restartPoint != 0) {
                outputStream.println("rest " + restartPoint);
                restartPoint = 0;
                // TODO: Interpret server response here
                getServerReply();
            }
     
            // Send the command
            outputStream.println(command);
     
            return isPositivePreliminaryResponse(getServerReply());
        }
     
    public boolean executeDataCommand(String command, OutputStream out)
            throws IOException
        {
            // Open a data socket on this computer
            ServerSocket serverSocket = new ServerSocket(0);
            if (!setupDataPort(command, serverSocket)) return false;
            Socket clientSocket = serverSocket.accept();
     
            // Transfer the data
            InputStream in = clientSocket.getInputStream();
            transferData(in, out);
     
            // Clean up the data structures
            in.close();
            clientSocket.close();
            serverSocket.close();
     
            return isPositiveCompleteResponse(getServerReply());    
        }
     
    public boolean readDataToFile(String command, String fileName)
            throws IOException
        {
            // Open the local file
            RandomAccessFile outfile = new RandomAccessFile(fileName, "rw");
     
            // Do restart if desired
            if (restartPoint != 0) {
                debugPrint("Seeking to " + restartPoint);
                outfile.seek(restartPoint);
            }
     
            // Convert the RandomAccessFile to an OutputStream
            FileOutputStream fileStream = new FileOutputStream(outfile.getFD());
            boolean success = executeDataCommand(command, fileStream);
     
            outfile.close();
     
            return success;
        }
     
    public boolean downloadFile(String serverPath, String localPath)
            throws IOException
        {
            return readDataToFile("retr " + serverPath, localPath);
        }
     
     public static void main(String[] args)
        {
            FTPConnection f = new FTPConnection("ftp.XXXX.com","login","password");
            try {
                System.out.println(f.connectLogB());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            try {
                System.out.println(f.uploadFile("essai.txt","C:\\Documents and Settings\\Bureau\\erreur ftp mx.txt"));
            } catch (IOException ex) {
                ex.printStackTrace();
            }
     
        }
    autre point important, sur place quand il est utilisé un logiciel payant de transfert ftp ça marche.....

    si quelqu'un peut m'aide.... merci d'avance.

  2. #2
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    251
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 251
    Par défaut
    Bonjour à tous,

    Ce n'est pas un problème qui vient ni du serveur, ni du code. J'ai essayé sur plusieurs autres connexions et j'en ai trouvé une avec qui ça marche!
    Je souhaiterai savoir ce qui peut provoquer cela au niveau du réseau interne. Car je ne comprends pourquoi la connexion au serveur ftp passe, mais que le transfert de data soit bloqué ? Et pourquoi quand j'utilise FTPExpert2 il n'y a pas de blocage ?

    Merci d'avance pour votre aide. Je suis preneur de toutes propositions :-)
    bonne soirée

  3. #3
    Membre Expert
    Homme Profil pro
    Dév. Java & C#
    Inscrit en
    Octobre 2002
    Messages
    1 414
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Dév. Java & C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2002
    Messages : 1 414
    Par défaut
    Bonjour

    As-tu examiné ton problème sous l'angle du "mode actif" et "mode passif" [1]?

    [1] wikipedia FTP

  4. #4
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    251
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 251
    Par défaut
    Bonjour et merci,

    Effectivement ça doit venir du mode. Je suis en mode actif alors que FTPExpert2 est en mode passif.

    Je fais les modifications et vous tiens au courant.

    Merci

  5. #5
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    251
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 251
    Par défaut
    Bonjour,

    Mon problème était bien le mode choisi.
    En mode passif tout marche.

    Merci beaucoup et bonne journée.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 30/09/2014, 22h16
  2. java.net.SocketException: Connection reset
    Par Onexus dans le forum Entrée/Sortie
    Réponses: 1
    Dernier message: 01/05/2010, 13h18
  3. Réponses: 5
    Dernier message: 10/01/2009, 13h44
  4. Réponses: 6
    Dernier message: 04/07/2008, 17h58
  5. Exception java.net.SocketException connection reset
    Par cigala5555 dans le forum Entrée/Sortie
    Réponses: 1
    Dernier message: 22/05/2008, 22h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo