日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java socket 连接异常_java.net.SocketException:软件导致连接中止:套接字写错误

發布時間:2025/3/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java socket 连接异常_java.net.SocketException:软件导致连接中止:套接字写错误 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參見英文答案 >

Official reasons for “Software caused connection abort: socket write error”????????????????????????????????????11

我正在嘗試將圖像從Java桌面應用程序發送到J2ME應用程序.問題是我得到這個例外:

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

我在網上看了四周,雖然這個問題并不罕見,但我無法找到具體的解決方案.在傳輸之前,我將圖像轉換為字節數組.這些是分別在桌面應用程序和J2ME上找到的方法

public void send(String ID, byte[] serverMessage) throws Exception

{

//Get the IP and Port of the person to which the message is to be sent.

String[] connectionDetails = this.userDetails.get(ID).split(",");

Socket sock = new Socket(InetAddress.getByName(connectionDetails[0]), Integer.parseInt(connectionDetails[1]));

OutputStream os = sock.getOutputStream();

for (int i = 0; i < serverMessage.length; i++)

{

os.write((int) serverMessage[i]);

}

os.flush();

os.close();

sock.close();

}

private void read(final StreamConnection slaveSock)

{

Runnable runnable = new Runnable()

{

public void run()

{

try

{

DataInputStream dataInputStream = slaveSock.openDataInputStream();

int inputChar;

StringBuffer results = new StringBuffer();

while ( (inputChar = dataInputStream.read()) != -1)

{

results.append((char) inputChar);

}

dataInputStream.close();

slaveSock.close();

parseMessage(results.toString());

results = null;

}

catch(Exception e)

{

e.printStackTrace();

Alert alertMsg = new Alert("Error", "An error has occured while reading a message from the server:\n" + e.getMessage(), null, AlertType.ERROR);

alertMsg.setTimeout(Alert.FOREVER);

myDisplay.setCurrent(alertMsg, resultScreen);

}

}

};

new Thread(runnable).start();

}

我通過LAN發送消息,當我發送短消息而不是圖像時,我沒有問題.此外,我使用wireshark,似乎桌面應用程序只發送部分消息.任何幫助將高度贊賞.此外,一切都適用于J2ME模擬器.

總結

以上是生活随笔為你收集整理的java socket 连接异常_java.net.SocketException:软件导致连接中止:套接字写错误的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。