android c#websocket传送图片

举报
风吹稻花香 发表于 2021/06/06 00:06:19 2021/06/06
【摘要】 这个失败了,传一张可以,一直传就报错: public static void startHttpClientWebSocket() { AsyncHttpClient.getDefaultInstance().websocket("ws://192.168.27.54:" + PORT, null, new AsyncHttpClient.WebSocketConnec...

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


  
  1. public static void startHttpClientWebSocket() {
  2. AsyncHttpClient.getDefaultInstance().websocket("ws://192.168.27.54:" + PORT, null, new AsyncHttpClient.WebSocketConnectCallback() {
  3. @Override
  4. public void onCompleted(Exception ex, WebSocket webSocket) {
  5. Log.i(TAG, "----------------startHttpClientWebSocket------websocket---onCompleted-" + webSocket);
  6. if (ex != null) {
  7. ex.printStackTrace();
  8. return;
  9. }
  10. webSocket.setDataCallback(new DataCallback() {
  11. @Override
  12. public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
  13. Log.d("Socket", "接收到:" + new String(bb.getAllByteArray()));
  14. }
  15. });
  16. webSocket.setClosedCallback(new CompletedCallback() {
  17. @Override
  18. public void onCompleted(Exception ex) {
  19. if (ex != null) {
  20. Log.d("Socket", "setClosedCallback出错");
  21. return;
  22. }
  23. Log.d("Socket", "setClosedCallback");
  24. }
  25. });
  26. webSocket.setEndCallback(new CompletedCallback() {
  27. @Override
  28. public void onCompleted(Exception ex) {
  29. if (ex != null) {
  30. Log.d("Socket", "setEndCallback出错");
  31. return;
  32. }
  33. Log.d("Socket", "setEndCallback");
  34. }
  35. });
  36. webSocket.setWriteableCallback(new WritableCallback() {
  37. @Override
  38. public void onWriteable() {
  39. Log.d("Socket", "onWriteable");
  40. }
  41. });
  42. mywebSocket=webSocket;
  43. final String order = "测试信息";
  44. Util.writeAll(webSocket, order.getBytes(), new CompletedCallback() {
  45. @Override
  46. public void onCompleted(Exception ex) {
  47. if (ex != null) {
  48. Log.d("Socket", "writeAll出错");
  49. return;
  50. }
  51. Log.d("Socket", "发送了:" + order);
  52. }
  53. });
  54. }
  55. });
  56. }

 


  
  1. last_sendDate=new Date(System.currentTimeMillis());
  2. YuvImage yuvimage1 = new YuvImage(mNv21Data, ImageFormat.NV21, tmpWidth, tmpHeight, null);
  3. ByteArrayOutputStream baosa = new ByteArrayOutputStream();
  4. yuvimage1.compressToJpeg(new Rect(0, 0, tmpWidth, tmpHeight), 100, baosa);// 80--JPG图片的质量[0-100],100最高
  5. byte[] rawImage1 = baosa.toByteArray();
  6. if (AsynUtils.mywebSocket != null) {
  7. BitmapFactory.Options optionsCache = new BitmapFactory.Options();
  8. optionsCache.inPreferredConfig = Bitmap.Config.RGB_565;
  9. // final Bitmap bitmap = BitmapFactory.decodeByteArray(rawImage1, 0, rawImage1.length, optionsCache);
  10. byte[] encode = Base64.encode(rawImage1, Base64.DEFAULT);
  11. String base64 = new String(encode);
  12. // String faceBase64 = bitmapToBase64(bitmap).replace("=", "").replace("/", "_").replace("+", "-").replace("\n", "");
  13. final String order = "测试信息";
  14. Util.writeAll(AsynUtils.mywebSocket, base64.getBytes(), new CompletedCallback() {
  15. @Override
  16. public void onCompleted(Exception ex) {
  17. if (ex != null) {
  18. Log.d("Socket", "writeAll出错");
  19. return;
  20. }
  21. // Log.d("Socket", "发送了:" + order);
  22. }
  23. });
  24. // AsynUtils.mywebSocket=null;
  25. }

 

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/103588003

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。