I am using x11vnc and I want to develop simple client for it. So, the work is:
and etc.
So, for example, I am using the next simple code:
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
String test = null;
try {
test = lnr.readLine();
System.out.println(test);
test = lnr.readLine();
System.out.println(test);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
System.exit(0);
The first message from server I got without errors (first readLine). The next message is empty (or without any line terminator for readLine) and I have infinite loop. lnr.ready() not works for me.
So, how can I read from socket when data from socket sometimes have no "\n", "\r", "\r\n" or if the socket buffer is empty?
The only RFB/VNC message that is terminated by a newline is the initial version exchange. In fact the RFB/VNC protocol is somewhat deficient in that it does not have any unique message framing; you have to process every message or you will lose your place. You probably will need to read directly from the socket or from the InputStreamReader. Wrapping it with LineNumberReader won't work.
The best reference I have found on the RFB/VNC protocol: http://tigervnc.org/cgi-bin/rfbproto