1

I'm making a server application which streams a multidimensional array. But when it should start streaming, i'm getting a socket write error. Here's the code: Part 1

public class Server {
    ServerSocket server;
    DataInputStream quitDis;
    int port = 8090;
     DataInputStream dis;
    DataOutputStream dos;
    Socket socket = null;

    public Server(){
        quitDis = new DataInputStream(System.in);

        try{
            System.out.println("Server starting...");
            server = new ServerSocket(port);
            System.out.println("Server started. It runs on IP: " +        Inet4Address.getLocalHost().getHostAddress() +" Port: "+ port);
        } catch (IOException e){
            System.out.println("Port is used");
        }

        try {
            while(quitDis.available() == 0){
                socket = server.accept();
                System.out.println("Anfrage von " + socket.getInetAddress().getHostAddress());
                dis = new DataInputStream(socket.getInputStream());
                dos = new DataOutputStream(socket.getOutputStream());
                int request = dis.readInt();
                    if(request == 1){
                        System.out.println("Transmitting matrix 1");
                        new sendArray(dos, matrix1);
                    }else if(request == 2){
                        System.out.println("Transmitting matrix 2");
                        new sendArray(dos, matrix2);
                    }else if(request == 3){
                        System.out.println("Transmitting matrix 3");
                        new sendArray(dos, matrix3);
                    }else if(request == 4){
                        System.out.println("Transmitting matrix 4");
                        new sendArray(dos, matrix4);
                    }else if(request == 5) {
                        System.out.println("Transmitting matrix 5");
                        new sendArray(dos, matrix5);
                    }
                else{
                    System.out.println("Invalid request");
                    System.out.println("Request: " + request);
                }

                System.out.println("Reuest has been proccessed. Waiting for new requests");

        }
        System.out.println("Server stopped");
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            dis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

Part 2

import java.io.DataOutputStream;
import java.io.IOException;

public class sendArray {
    int x;
    int y;
    DataOutputStream dos = null;
    public sendArray(DataOutputStream dos,boolean[][] matrix) throws IOException {
        this.dos = dos;
        for(x = 0; x <= 4; x++){
            for(y = 0;y <= 4; y++){
                try {
                    System.out.println(matrix[x][y]);
                    dos.writeBoolean(matrix[x][y]);             <---
                    dos.flush();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}

The error occurs at the marked line

java.net.SocketException: Software caused connection abort: socket write error

The client connects to the server and sends the matrix number as an integer. I hope you can help me

littlegigant
  • 11
  • 1
  • 1

0 Answers0