安卓:插座 - java.net.SocketException异常:SENDTO失败:EPIPE(中断的管道) [英] Android : Socket - java.net.SocketException: sendto failed: EPIPE (Broken pipe)

查看:2690
本文介绍了安卓:插座 - java.net.SocketException异常:SENDTO失败:EPIPE(中断的管道)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图与服务器使用套接字连接。连接管被分解如下所示的例外

I am trying to make connection with server using socket. The connection pipe is broken as shown below exceptions.

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)

这里是code,并在此行 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();
        }
    }

注意:如果我关闭套接字连接直接效果还算不错。但我想保持连接活着还是我手动关闭套接字连接。停止按钮的onclick我关闭连接。

我做了谷歌搜索,但没有找到一个方法来解决这个问题。任何建议或想法如何解决这个问题?

I did a Google search, but didn't find a way to fix this. Any suggestions or idea how to solve this ??

帮助将AP preciated。

Help will be appreciated.

推荐答案

对端关闭了连接,而你正在写它。这通常意味着你把它的东西它不明白。它是也许是一个HTTP服务器?或者说,你有没有在您的客户端code实现的其他一些协议?

The peer closed the connection while you were writing to it. That usually means you sent it something it didn't understand. Is it perhaps an HTTP server? Or some other protocol that you haven't implemented in your client code?

这篇关于安卓:插座 - java.net.SocketException异常:SENDTO失败:EPIPE(中断的管道)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆