我们如何确定一张图片结束而另一张图片开始? 我正在截取屏幕并将其发送到服务器。 我的代码只发送第一个屏幕截图到服务器。
客户端:
线程1正在使用Screenshtot 线程2正在向服务器发送屏幕截图。
主题2
Thread sendingScreenShotThread = new Thread () {
public void run () {
//Sending Screen to Server
try {
ImageIO.write(screencapture, "jpg", baos);
ImageInBytes = baos.toByteArray();
dos.write(ImageInBytes);
File Rif = new File(System.currentTimeMillis() + ".jpg");
ImageIO.write(screencapture, "jpg", Rif);
System.out.println("thread2 is running...");
} catch (IOException e) {
e.printStackTrace();
}
finally{
try {
baos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
服务器
try{
boolean processing=true;
while(processing)
{
try {
byte[] buffer = new byte[1024];
out = new BufferedOutputStream(new FileOutputStream(path+ System.currentTimeMillis() + ".jpg"));
while ((in.read(buffer)) >= 0) {
out.write(buffer);
System.out.println("Image file written successfully");
}
} catch (Exception e) {
}finally {
processing=false;
if (out != null) out.close();
}
}
}
finally{
out.close();
clientSocket.close();
serversock.close();
}