作者sean2449 (肉松)
看板AndroidDev
标题[问题] 有关於Socket 传送和接收byte[]的问题
时间Wed Aug 24 22:28:13 2011
小弟最近要写一个Server and Client的程式
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
其中bmp是Client端用相机照起来的图档
Client用
DataOutputStream output = new DataOutputStream(clientSocket.getOutputStream());
output.write(b);
output.flush();
然後Server接收端用
byte[] receive = new byte[2048];
DataInputStream input = new DataInputStream(socket.getInputStream());
while ( input.read(receive) != -1 ) {
....
....
}
但是Server端似乎会停在input.read就不动了
或是有其他方法能够传送吗??
拜托大神们救救小弟吧Q_Q
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.144.132
1F:→ Killercat:你的socket确定是对的吗 TCP来讲有Listen/Accept socket 08/25 05:48
2F:→ Killercat:不是new一个Socket就能用的 08/25 05:48
3F:推 LaPass:ServerSocket SS = new ServerSocket(你的port); 08/25 07:59
4F:→ LaPass:Socket S = SS.Accept(); 08/25 08:00
5F:→ LaPass:Server端要这样写,大小写以及拼字我没检查。 08/25 08:00
6F:→ LaPass:还有,没收到东西的话,程式会停在input.read()那边没错 08/25 08:01