android c#websocket传送图片

这个失败了,传一张可以,一直传就报错:

  public static void startHttpClientWebSocket() {
        AsyncHttpClient.getDefaultInstance().websocket("ws://192.168.27.54:" + PORT, null, new AsyncHttpClient.WebSocketConnectCallback() {
            @Override
            public void onCompleted(Exception ex, WebSocket webSocket) {

                Log.i(TAG, "----------------startHttpClientWebSocket------websocket---onCompleted-" + webSocket);
                if (ex != null) {
                    ex.printStackTrace();
                    return;
                }
                webSocket.setDataCallback(new DataCallback() {
                    @Override
                    public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
                        Log.d("Socket", "接收到:" + new String(bb.getAllByteArray()));
                    }
                });

                webSocket.setClosedCallback(new CompletedCallback() {
                    @Override
                    public void onCompleted(Exception ex) {
                        if (ex != null) {
                            Log.d("Socket", "setClosedCallback出错");
                            return;
                        }
                        Log.d("Socket", "setClosedCallback");
                    }
                });

                webSocket.setEndCallback(new CompletedCallback() {
                    @Override
                    public void onCompleted(Exception ex) {
                        if (ex != null) {
                            Log.d("Socket", "setEndCallback出错");
                            return;
                        }
                        Log.d("Socket", "setEndCallback");
                    }
                });

                webSocket.setWriteableCallback(new WritableCallback() {
                    @Override
                    public void onWriteable() {
                        Log.d("Socket", "onWriteable");
                    }
                });
                mywebSocket=webSocket;
                final String order = "测试信息";

                Util.writeAll(webSocket, order.getBytes(), new CompletedCallback() {
                    @Override
                    public void onCompleted(Exception ex) {
                        if (ex != null) {
                            Log.d("Socket", "writeAll出错");
                            return;
                        }
                        Log.d("Socket", "发送了:" + order);
                    }
                });
            }
        });

    }

 

 last_sendDate=new Date(System.currentTimeMillis());
                                YuvImage yuvimage1 = new YuvImage(mNv21Data, ImageFormat.NV21, tmpWidth, tmpHeight, null);
                                ByteArrayOutputStream baosa = new ByteArrayOutputStream();
                                yuvimage1.compressToJpeg(new Rect(0, 0, tmpWidth, tmpHeight), 100, baosa);// 80--JPG图片的质量[0-100],100最高
                                byte[] rawImage1 = baosa.toByteArray();

                                if (AsynUtils.mywebSocket != null) {
                                    BitmapFactory.Options optionsCache = new BitmapFactory.Options();
                                    optionsCache.inPreferredConfig = Bitmap.Config.RGB_565;
                                    //  final Bitmap bitmap = BitmapFactory.decodeByteArray(rawImage1, 0, rawImage1.length, optionsCache);
                                    byte[] encode = Base64.encode(rawImage1, Base64.DEFAULT);
                                    String base64 = new String(encode);

                                    // String faceBase64 = bitmapToBase64(bitmap).replace("=", "").replace("/", "_").replace("+", "-").replace("\n", "");
                                    final String order = "测试信息";
                                    Util.writeAll(AsynUtils.mywebSocket, base64.getBytes(), new CompletedCallback() {
                                        @Override
                                        public void onCompleted(Exception ex) {
                                            if (ex != null) {
                                                Log.d("Socket", "writeAll出错");
                                                return;
                                            }
                                            //  Log.d("Socket", "发送了:" + order);
                                        }
                                    });
                                    //  AsynUtils.mywebSocket=null;
                                }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值