这个失败了,传一张可以,一直传就报错:
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;
}