السلام عليكم يا إخوة ..
واجهتني مشكلة لا أدري ما سببها.
في طرف السيرفر عندما أقوم بالإرسال فإنه يتم الإستقبال من الطرف الاخر و هو Client , لكن بعد فترة من النجاح في الإرسال و الإستقبال يحدث التالي :
يصبح الزبون في حالة انتظار لأن يقرأ البيانات الواردة من السيرفر لكنه لا يستطيع و يبقى في حالة توقف .. و حقيقة لا أدري ما سبب ذلك.
الكود المسئول عن النقل في السيرفر :
protected static void watchRemotely(String name){
try {
int index = findClient(name);
ClientRecord client = clients.get(index);
client.getOutStream().writeUTF(Marks.SEND_DESKTOP);
int width = client.getInStream().readInt();
int heigh = client.getInStream().readInt();
int nwidth = width / 2;
int nheigh = heigh / 2;
RemoteDeskTopFrame frame = new RemoteDeskTopFrame();
frame.setSize(nwidth, nheigh);
frame.setVisible(true);
boolean reciveNow = true;
Graphics g = RemoteDeskTopFrame.rdf.getGraphics();
while( reciveNow ){
byte[] buf = new byte[1280000];
client.getInStream().read(buf);
int x = client.getInStream().readInt();
int y = client.getInStream().readInt();
ByteArrayInputStream bas = new ByteArrayInputStream(buf);
BufferedImage img = ImageIO.read(bas);
g.drawImage(img, 0, 0, nwidth, nheigh, frame);
g.drawRect(x, y, 10, 10);
RemoteDeskTopFrame.rdf.repaint();
client.getOutStream().writeUTF("-nothing");
}
} catch (IOException ex) {
Logger.getLogger(ServerConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}الكود الخاص بالنقل و الإستقبال من الزبون :
class Recive implements Runnable{
public void run() {
String mark;
while (true) {
try {
mark = in_stream.readUTF();
if( mark.equals(Marks.SEND_DESKTOP) ){
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int width = dim.width;
int heigh = dim.height;
out_stream.writeInt(width);
out_stream.writeInt(heigh);
boolean sendNow = true;
Robot robot = new Robot();
BufferedImage img = null;
Point point;
while( sendNow ){
img = robot.createScreenCapture(new Rectangle(dim));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", stream);
byte[] buf = stream.toByteArray();
out_stream.write(buf);
out_stream.flush();
System.out.println("0");
point = MouseInfo.getPointerInfo().getLocation();
int x = point.x;
int y = point.y;
out_stream.writeInt(x);
out_stream.writeInt(y);
mark = in_stream.readUTF();
if( mark.equals(Marks.STOP_MONITOR) )
sendNow = false;
else
Thread.sleep(100);
}
}
} catch (InterruptedException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
} catch (AWTException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}حتى أكون دقيق أكثر المشكلة ظهرت بعد إدخال الكود التالي إلى السيرفر : و هو الكود الخاص بإستقبال قيم x و y من الزبون ..
int x = client.getInStream().readInt();
int y = client.getInStream().readInt();و أيضا الكود التالي في طرف الزبون :
int x = point.x;
int y = point.y;
out_stream.writeInt(x);
out_stream.writeInt(y);
