Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i write a server in java that sending images for phone and reading data from it at the same time, the phone sending the position of touch and the problem that stuck on read if there is no touch on the phone, and it's been very slowlly
Java
private void whileConnecting() throws IOException, AWTException {  
    byte[] buffer;
    while(connection.isConnected()){

        x = input.readFloat();
        y = input.readFloat();
        System.out.println("x = y");

    capture = robot.createScreenCapture(screenRectangle);//capture whole screen 
    baos = new ByteArrayOutputStream();//this object will receive the capture image
    ImageIO.write(capture, "jpg", baos);//chose "JPG" because this is the best image's format from size and quality 
    baos.flush();//flush all the bytes 
    System.out.println("Size of baos = " + baos.size());
    buffer = baos.toByteArray();//convert ByteArrayOutputStream to bytes array that can to send it over socket
    baos.close();//close the ByteArrayOutputStream to can write in it again, if not closed it will append images
    output.writeObject(buffer);//send the image's byte array over the socket
    output.flush();//flush all bytes 
    }
}   
Posted

1 solution

I would create two sockets with different port numbers, one for the images and other for receiving the data.
 
Share this answer
 
Comments
Member 11325219 23-Apr-15 6:29am    
Good idea :)
thanks dod :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900