Problem
How to send UTF-8 data between the server and the client, if I can use on client only
inputStream.read()
?
Docs
Reads a single byte from this stream and returns it as an integer in
the range from 0 to 255. Returns -1 if the end of the stream has been
reached.
Without reader.readLine() and any another. (With reader I cant see end of stream)
Help please!
(full code:)
int c;
String str = new String();
while ((c = inputStream.read( )) != -1)
{
char ch = (char)c;
if(ch == '\n')
{
Log.v("", str);
final String data = str;
runOnUiThread(new Runnable()
{
@Override
public void run()
{
String put[] = data.split("#");
try
{
//cmd parsing
}
catch(Exception e)
{
//stop connection
}
}
});
str = "";
}else{
str += Character.toString(ch);
}
}
//Communication error
Help please
You might want to take a look at this previous post. There’s a couple of good options on there. The
read()method can be overloaded with different parameters, so you can read one byte, or n bytes. Check out the full documentation here. Basically, you’ll have to read in the raw bytes, then convert them to ASCII characters. Also, I’m curious as to why you can’t useBufferedReaderor an equivalent class?