gpt4 book ai didi

java - Android : Socket - java.net.SocketException: sendto 失败: EPIPE (Broken pipe)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:31 24 4
gpt4 key购买 nike

我正在尝试使用套接字与服务器建立连接。连接管坏了如下图异常。

01-31 14:47:16.536: W/System.err(27255): java.net.SocketException: sendto failed: EPIPE (Broken pipe)
01-31 14:47:16.550: W/System.err(27255): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:496)
01-31 14:47:16.550: W/System.err(27255): at libcore.io.IoBridge.sendto(IoBridge.java:465)
01-31 14:47:16.550: W/System.err(27255): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
01-31 14:47:16.550: W/System.err(27255): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
01-31 14:47:16.664: W/NetworkManagementSocketTagger(24437): setKernelCountSet(10021, 1) failed with errno -2
01-31 14:47:16.684: W/System.err(27255): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
01-31 14:47:16.693: W/System.err(27255): at java.io.DataOutputStream.write(DataOutputStream.java:98)
01-31 14:47:16.693: W/System.err(27255): at java.io.OutputStream.write(OutputStream.java:82)
01-31 14:47:16.693: W/System.err(27255): at com.x.x.y.sendRec(y.java:460)
01-31 14:47:16.693: W/System.err(27255): at com.x.x.y.access$0(y.java:384)
01-31 14:47:16.693: W/System.err(27255): at com.x.x.y$2.run(y.java:363)
01-31 14:47:16.693: W/System.err(27255): at java.lang.Thread.run(Thread.java:856)
01-31 14:47:16.693: W/System.err(27255): Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.Posix.sendtoBytes(Native Method)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.Posix.sendto(Posix.java:146)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.IoBridge.sendto(IoBridge.java:463)

这是代码,在这一行 outStreamRec.write(bData); 抛出异常。

    try {
port = 86;
byterecv = new byte[1040];
clientRec = new Socket();
clientRec.connect(new InetSocketAddress("192.168.1.36", port));
System.out.println("Just connected to " + clientRec.getRemoteSocketAddress());
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
while (true) {
try {
System.out.println("Connecting to " + ServerUrl.url + " on port " + port);
OutputStream outToServerRec = clientRec.getOutputStream();
DataOutputStream outStreamRec = new DataOutputStream(outToServerRec);

outStreamRec.write(bData);

InputStream inFromServerPlay = clientRec.getInputStream();
DataInputStream inStreamPlay = new DataInputStream(inFromServerPlay);
while ((lstream = inStreamPlay.read(byterecv)) != -1) {
System.out.println("startrec bytearray -- " + byterecv.length);
bos1.write(byterecv, 0, lstream);
}
if (stopcall == true) {
clientRec.close();
break;
}

} catch (IOException e) {
e.printStackTrace();
}
}

注意:如果我关闭套接字连接立即工作正常。但是我想保持连接仍然存在我手动关闭套接字连接。单击停止按钮我将关闭连接。

我在网上搜索过,但没有找到解决此问题的方法。

最佳答案

在您写入时,对方关闭了连接。这通常意味着您向它发送了它不理解的内容。它可能是一个 HTTP 服务器吗?或者您尚未在客户端代码中实现的其他一些协议(protocol)?

关于java - Android : Socket - java.net.SocketException: sendto 失败: EPIPE (Broken pipe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14622700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com