im using guava and weberknecht to convert an inputStream to a string and connect to a websocket [see this post]. Weberknecht threw me out, so im trying a very simple Socket-Connection to get any answer from the server. The Problem is, i can’t read the inputStream. I don’t know why.
NOTE:
On Iphone the Websocket-Server works. [i know “websocket /= socket” … im just trying everything here to get ANY answer from the server]
My code:
try {
Socket sock = new Socket("62.212.88.234", 15000);
OutputStream out = sock.getOutputStream();
InputStream in = sock.getInputStream();
Log.e("SKT", "Reading input [! PROBLEM HERE !]");
String string = CharStreams.toString(new InputStreamReader(in,
"UTF-8"));
Log.e("SKT", "Answer [! NEVER REACHED !]:" + string);
sock.close();
} catch (UnknownHostException e) {
Log.e("SKT", "UnknownHostException: " + e.getMessage());
} catch (IOException e) {
Log.e("SKT", "IOException: " + e.getMessage());
}
Thanks for the Help in advance.
The documentation for
CharStreams.toStringsays:My guess is that the remote end does not close the socket, so there’s no end-of-stream to consume, thus the freeze.