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:软件导致连接中止:套接字写错误的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java Parallel gc_JVM
- 下一篇: java 线程一直运行状态_详解JAVA