Connection reset by peer: socket write error

x46

Mitglied
Ich habe bei folgenden den Error:
Java:
java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(Unknown Source)
    at java.net.SocketOutputStream.write(Unknown Source)
    at java.nio.file.Files.copy(Unknown Source)
    at java.nio.file.Files.copy(Unknown Source)
    at x46.Server.Server_in.run(Server_in.java:59)
    at java.lang.Thread.run(Unknown Source)
Mein Client (senden der Datei):
Java:
Socket client = new Socket("localhost", 16102);
        // strems
        // out
        OutputStream outStream = client.getOutputStream();
        PrintWriter out = new PrintWriter(outStream);
 
        // in
        InputStream inStream = client.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(inStream));
     
        // -------------------------------------------------------
     
        File file = new File("send.zip");
        // init array with file length
        byte[] bytesArray = new byte[(int) file.length()];
          FileInputStream fis = new FileInputStream(file);
          fis.read(bytesArray); //read file into bytes[]
          fis.close();
 
          outStream.write(bytesArray);
          outStream.flush();
       
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Server(empfängt die Datei):
Java:
        try {
            ExecutorService executor = Executors.newFixedThreadPool(2);
            // server starten
            ServerSocket server01 = new ServerSocket(16102);
            System.out.println("Warte auf clients auf dem Port " + server01.getLocalPort());
            // --------------------------------------------------------------
            while (true) {
                // connection aktiviren
                Socket connection = server01.accept();
                System.out.println("Client verbingung unter: " + connection.getRemoteSocketAddress());
                // -------------------------------------------------------------------
                // strems
                // out
                OutputStream outStream = connection.getOutputStream();
                PrintWriter out = new PrintWriter(outStream);
                ObjectOutputStream oos = new ObjectOutputStream(outStream);
                // in
                InputStream inStream = connection.getInputStream();
                BufferedReader in = new BufferedReader(new InputStreamReader(inStream));
                // ------------------------------------------------------------
                // Path path = Paths.get("test.zip");
                File f = new File("test.zip");
                Files.copy(f.toPath(), outStream);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
(das Programm ist um eine zip Datei zu verschicken)
Also woher kommt der Error?
 
Zuletzt bearbeitet:

mihe7

Top Contributor
Für den Empfang bietet es sich für gewöhnlich an, auch etwas zu lesen...

Du musst serverseitig den inStream auch verwenden. Und die ganzen Writer/Reader-Geschichten schmeißt Du am besten ganz raus: Du verschickst eine Zip-Datei, also binäre Daten und keine Zeichenketten.
 

mrBrown

Super-Moderator
Mitarbeiter
Wie im anderen Thread gesagt: nimm für den Client auch die Files-Variante, bei mir läuft es damit problemlos.
 

mrBrown

Super-Moderator
Mitarbeiter
Dieses hier: Files.copy(file.toPath(), outStream), statt dem händischem Einlesen und Senden der Datei.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
Z Socket Connection reset by peer nur per IP nicht über localhost Netzwerkprogrammierung 13
G Exception: Connection reset by peer: socket write error Netzwerkprogrammierung 2
IT-MaD Connection reset by peer: socket write error Netzwerkprogrammierung 2
F Probleme mit Connection Reset bei Telnet Verbindung Netzwerkprogrammierung 1
R Socket InputStream readObject > Connection Reset Netzwerkprogrammierung 3
D Socket Socket absichtlich so schließen, dass Gegenseite java.net.SocketException: Connection reset wirft Netzwerkprogrammierung 4
K Socket Exception Connection reset Netzwerkprogrammierung 9
VfL_Freak Socket SocketException: Connection reset Netzwerkprogrammierung 11
D Client Server Problem, Methode readline() löst SocketException "Connection reset" aus Netzwerkprogrammierung 8
T Wie connection Reset abfragen/abfangen? Netzwerkprogrammierung 10
sparrow Connection Reset bei Webserver, Java WebStart als Client Netzwerkprogrammierung 9
B Multithreaded Server: Connection reset Netzwerkprogrammierung 4
T JDBC Verbindungsabbruch (Connection reset) Netzwerkprogrammierung 2
M SocketException: Connection reset Netzwerkprogrammierung 10
M seltsam: java.net.SocketException: Connection reset Netzwerkprogrammierung 1
Thalion TCP Connection zu langsam Netzwerkprogrammierung 2
S Client Server Connection Netzwerkprogrammierung 4
C Handle Connection Problem Netzwerkprogrammierung 3
L ssh connection; Zugriff auf 'screen' Prozess Netzwerkprogrammierung 5
C Client connection per Portforwarding auf einen lokalen Serverport Netzwerkprogrammierung 3
M Connection refused? Netzwerkprogrammierung 2
D Connection refused Netzwerkprogrammierung 3
B Client/Server Connection Problem Netzwerkprogrammierung 2
C Socket Connection refused bei Internetverbindung - Welcher Port? Netzwerkprogrammierung 5
C Socket Socket: Connection timed out Netzwerkprogrammierung 3
T Empfangen klappt Senden nicht - Connection timed out Netzwerkprogrammierung 12
H java.net.ConnectException: Connection refused Netzwerkprogrammierung 3
RELAXccc HTTP Connection timed out: connect ?an was kann es liegen? Netzwerkprogrammierung 4
N Socket verliert die Connection. Netzwerkprogrammierung 4
A UCP Connection über Proxy möglich? Netzwerkprogrammierung 7
M RMI - Connection Problem Netzwerkprogrammierung 7
trash HTTP Internet Connection bei Proxy ?! Netzwerkprogrammierung 3
H RMI Connection refused bei RMI-Registry Netzwerkprogrammierung 10
S SSH-Connection - Auto-Vervollständigung mittels TAB Netzwerkprogrammierung 4
A Chatprogramm: Connection refused Netzwerkprogrammierung 4
T RMI RMI und VPN - callbackObject Connection refused Netzwerkprogrammierung 13
A Socket Client Server Connection wird aufgebaut aber keine daten geschickt. Netzwerkprogrammierung 5
J Connection Speed Test ohne Applet Netzwerkprogrammierung 5
0din Connection refused bei localhost?! Netzwerkprogrammierung 7
M FTP-Connection über FTP-Proxy Netzwerkprogrammierung 20
A RMI java.rmi.ConnectException: Connection refused to host: 1 Netzwerkprogrammierung 4
M chat funktioniert nicht (Connection refused: connect) Netzwerkprogrammierung 3
G InputStreamReader lässt TCP-Connection offen Netzwerkprogrammierung 9
X URL connection Problem Netzwerkprogrammierung 3
R ConnectException: Connection refused to host: 192.168.1.4 ? Netzwerkprogrammierung 8
tfa RMI-Problem: Connection refused to host: 127.0.0.2 Netzwerkprogrammierung 4
G Connection zu MySQL ohne ODBC Netzwerkprogrammierung 8
B RMI & Connection refused to host Netzwerkprogrammierung 12
G httpUnit: Connection timed out Netzwerkprogrammierung 3
lhein java.io.IOException: Unable to establish loopback connection Netzwerkprogrammierung 4
Paule Connection Applet Servlet ohne Socket bzw RMI Netzwerkprogrammierung 2
G MAC / IP Connection Netzwerkprogrammierung 10
M Problem: connection abbrechen und login erkennen Netzwerkprogrammierung 2
M Umlaute gehen bei URL Connection verloren Netzwerkprogrammierung 6
B RMI Connection Problem Netzwerkprogrammierung 13
T Dateien wia P2P Connection versenden Netzwerkprogrammierung 2
D Socketverbindung schlägt fehl - Connection refused: connect Netzwerkprogrammierung 4
H java.net.SocketException: Software caused connection abort Netzwerkprogrammierung 4
R FTP Connection zu Server Netzwerkprogrammierung 4
M Ausgangsport für FTp-Connection festlegen??? Netzwerkprogrammierung 3
M ObjectOutputStream reset gibt IOException Netzwerkprogrammierung 4
M Socket peer to peer Verbindung zwischen Java und Matlab Netzwerkprogrammierung 0
T Peer-to-Peer Anwendung Netzwerkprogrammierung 2
F Peer to Peer Verbindung zwischen mehreren Clients? Netzwerkprogrammierung 8
F peer to peer Netzwerkprogrammierung 2

Ähnliche Java Themen

Neue Themen


Oben