R
R
Hello everybody.
I've got very stange situation.
I have a client using Socket and server applicaton using ServerSocket.
Server reads sth from client with this code:
while (-1 != (read = is.read(buffer))) { /* 'is' is InputStream */
for (int i = 0; i < read; i++) {
sb.append((char)buffer); /* 'sb' is StringBuffer */
}
}
read method NEVER returns -1, when client sends eg a basic message:
os.write("why oh why? don't You see the end of this
text?".getBytes());
so I have to do a trick and I hate this solution - all messages are
terminated with fullstop eg. client sends:
os.write("why oh why? don't You see the end of this
text?.".getBytes());
and the server:
while (46 != (read = is.read())) { /* 46 stands for ASCI '.' */
sb.append((char)read);
}
it works now but it's so lame solution...
but on the other hand when server sends a message to client:
os.write("roger that and over ;-)".getBytes());
client can read it without any prblem using exactly the same code as
the first I show You:
while (-1 != (read = is.read(buffer))) {
for (int i = 0; i < read; i++) {
sb.append((char)buffer);
}
}
and that's why I am so confused
why does Socket's and ServerSocket's Streams differs?
Am I doing sth wrong?
I'm using Linux but it's not a case...
can You advise me sth?
thanks in advance
best regards
R
I've got very stange situation.
I have a client using Socket and server applicaton using ServerSocket.
Server reads sth from client with this code:
while (-1 != (read = is.read(buffer))) { /* 'is' is InputStream */
for (int i = 0; i < read; i++) {
sb.append((char)buffer); /* 'sb' is StringBuffer */
}
}
read method NEVER returns -1, when client sends eg a basic message:
os.write("why oh why? don't You see the end of this
text?".getBytes());
so I have to do a trick and I hate this solution - all messages are
terminated with fullstop eg. client sends:
os.write("why oh why? don't You see the end of this
text?.".getBytes());
and the server:
while (46 != (read = is.read())) { /* 46 stands for ASCI '.' */
sb.append((char)read);
}
it works now but it's so lame solution...
but on the other hand when server sends a message to client:
os.write("roger that and over ;-)".getBytes());
client can read it without any prblem using exactly the same code as
the first I show You:
while (-1 != (read = is.read(buffer))) {
for (int i = 0; i < read; i++) {
sb.append((char)buffer);
}
}
and that's why I am so confused
why does Socket's and ServerSocket's Streams differs?
Am I doing sth wrong?
I'm using Linux but it's not a case...
can You advise me sth?
thanks in advance
best regards
R