There is no such thing as a message in TCP. It is a byte-stream. If you want messages, you have to define and implement them yourself. In some simple cases, a line is a message. As you've said that isn't the case here, it is up to you to define.
Java: Distingushing between end of one message and end of the stream
سؤال
I'm writing a small program writing to the command line, using SSH, and therefore usually getting output after some input.
So now I'm reading that output like this:
new Thread() {
public void run() {
int character;
try {
while ((character = output.read()) != -1) {
string += character;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
So far, I'm controlling the end of the stream. However, I would like to be able to estimate the end of one message (which doesn't have to be just one line) by which I mean the remote output to the sent input, respectively.
Is there a possibility to do this?
For instance, when I login via SSH, I send the command "ssh user@server", and now that reading thread should only read the "user@server's password:" message and then free the object's lock so that the writing stream can go on. But I don't know how to do that...
المحلول
لا تنتمي إلى StackOverflow