关于android socket通信接收服务器数据问题 socketandroid数据手机 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看起来代码没有什么问题, nReadLen = dis.read(buffer, nIdx, nTotalLen - nIdx); 检查一下是否是下标有问题。 public static byte[] readInputStream(InputStream ins) { if (ins == null) { return null; } BufferedInputStream bis = new BufferedInputStream(ins); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { byte[] buffer = new byte[128]; int n = -1; while ((n = bis.read(buffer)) != -1) { bos.write(buffer, 0, n); } } catch (IOException e) { e.printStackTrace(); return null; } finally { if (bis != null) { try { bis.close(); } catch (IOException e) { e.printStackTrace(); } } } return bos.toByteArray(); }读完了所有的数据流以后 再进行byte数组操作。建议把网络操作放到线程里面。 read是阻塞读,一定要放在线程里面 read阻塞了,你从一个跳转过去出问题,要么就是权限问题或者什么东西忘记关了 while (nIdx < nTotalLen) 这里一直卡死了吧?转头又卡在read上了,没跑下去 服务器端该如何搭建 刚做Android,在网上下了一个代码,自己调试的时候出了问题,请大家帮我看看 请教android的安全软件开发 无奈~ 怎么在异步线程中实现Activity之间的跳转 安卓开发基础问题 Android中如何使用开源C库 No virtual keys found for device 问题求解 谷歌眼镜开发之认证 ProgressDialog无法使用 android wifi定位设置 surfaceView中的线程问题
nReadLen = dis.read(buffer, nIdx, nTotalLen - nIdx); 检查一下是否是下标有问题。 public static byte[] readInputStream(InputStream ins) {
if (ins == null) {
return null;
}
BufferedInputStream bis = new BufferedInputStream(ins);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[128];
int n = -1;
while ((n = bis.read(buffer)) != -1) {
bos.write(buffer, 0, n);
}
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return bos.toByteArray();
}
读完了所有的数据流以后 再进行byte数组操作。
建议把网络操作放到线程里面。