基本过程是android作为socket客户端将采集到的每一帧图像数据发送出去,PC作为服务器接收并显示每一帧图像实现远程监控。运行这个程序时 在模拟器上运行android程序时 在PC端能接受到图像 可是我把程序放到手机上 然后手机和电脑都连接了wlan PC端接收不到图像 每次都运行到红色字的部分,这是为什么啊??
android端:public void run() { try{ //将图像数据通过Socket发送出去 Socket tempSocket = new Socket(ipname, 6000); outsocket = tempSocket.getOutputStream(); ByteArrayInputStream inputstream = new ByteArrayInputStream(myoutputstream.toByteArray()); int amount; while ((amount = inputstream.read(byteBuffer)) != -1) { outsocket.write(byteBuffer, 0, amount); } myoutputstream.flush(); myoutputstream.close(); tempSocket.close();
} catch (IOException e) { e.printStackTrace(); }
}
javaPC端:public ImagePanel(ServerSocket ss) {
this.ss = ss;
System.out.println("11-----------"+ss);
}
public void getimage() {
System.out.println("123-----------");
Socket s = null;
try {
System.out.println("123-----------"+s);
s = this.ss.accept();
System.out.println("12-----------"+s);
System.out.println("连接成功!");
this.ins = s.getInputStream();
this.image = ImageIO.read(ins);
this.ins.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("链接异常-----------");
e.printStackTrace();
}
}
android端:public void run() { try{ //将图像数据通过Socket发送出去 Socket tempSocket = new Socket(ipname, 6000); outsocket = tempSocket.getOutputStream(); ByteArrayInputStream inputstream = new ByteArrayInputStream(myoutputstream.toByteArray()); int amount; while ((amount = inputstream.read(byteBuffer)) != -1) { outsocket.write(byteBuffer, 0, amount); } myoutputstream.flush(); myoutputstream.close(); tempSocket.close();
} catch (IOException e) { e.printStackTrace(); }
}
javaPC端:public ImagePanel(ServerSocket ss) {
this.ss = ss;
System.out.println("11-----------"+ss);
}
public void getimage() {
System.out.println("123-----------");
Socket s = null;
try {
System.out.println("123-----------"+s);
s = this.ss.accept();
System.out.println("12-----------"+s);
System.out.println("连接成功!");
this.ins = s.getInputStream();
this.image = ImageIO.read(ins);
this.ins.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("链接异常-----------");
e.printStackTrace();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货