我正在制作一个流式传输多维数组的服务器应用程序。但是当它应该开始流式传输时,我会收到套接字写入错误。这是代码: 第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();
}
}
}
第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();
}
}
}
}
}
错误发生在标记的行
java.net.SocketException: Software caused connection abort: socket write error
客户端连接到服务器并将矩阵编号作为整数发送。我希望你能帮助我