android c#websocket传送图片
【摘要】 这个失败了,传一张可以,一直传就报错:
public static void startHttpClientWebSocket() { AsyncHttpClient.getDefaultInstance().websocket("ws://192.168.27.54:" + PORT, null, new AsyncHttpClient.WebSocketConnec...
这个失败了,传一张可以,一直传就报错:
-
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;
-
}
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/103588003
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)