小弟socket,thread不太会,哪位大侠能帮助解决下问题,问题如下:
我做了一个C/S端的程序,服务器端截屏后发送
服务器端不停的截图和发送,但是客户端只接收到第2张图片
服务器端在发第三张图片是 ImageIO.write();方法处卡出且不报异常
发送线程的RUN:
public void run() {
try {
os=socket.getOutputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
while(true){
截取图片
BufferedImage image = (BufferedImage) new Snap(".","jpg).snapPhoto();
if(image!=null){
发送图片
try {
ImageIO.write(image, "gif", os);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}客户端接收:
public void run() {
//调整Label
clientFrame.getPanel().setBackground(Color.gray);
clientFrame.getLabel().setText("");
//拿inputstream
try {
is =socket.getInputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//连接服务器
try {
BufferedImage bi = ImageIO.read(is);
clientFrame.getLabel().setIcon(new ImageIcon(bi));
i=is.available(); //保存接收的图片
output(bi);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}急!
我做了一个C/S端的程序,服务器端截屏后发送
服务器端不停的截图和发送,但是客户端只接收到第2张图片
服务器端在发第三张图片是 ImageIO.write();方法处卡出且不报异常
发送线程的RUN:
public void run() {
try {
os=socket.getOutputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
while(true){
截取图片
BufferedImage image = (BufferedImage) new Snap(".","jpg).snapPhoto();
if(image!=null){
发送图片
try {
ImageIO.write(image, "gif", os);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}客户端接收:
public void run() {
//调整Label
clientFrame.getPanel().setBackground(Color.gray);
clientFrame.getLabel().setText("");
//拿inputstream
try {
is =socket.getInputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//连接服务器
try {
BufferedImage bi = ImageIO.read(is);
clientFrame.getLabel().setIcon(new ImageIcon(bi));
i=is.available(); //保存接收的图片
output(bi);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}急!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货