Reputation: 55
I have a C# Server and this Java client in Android Studio:
@Override
public void run() {
try {
Socket socket = new Socket("192.168.0.107", 7778);
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while (true) {
currentMessage = inFromServer.readLine();
System.out.println(currentMessage);
Thread.sleep(200);
}
}
catch(Exception e) {
System.out.print("Error: " + e.toString() + "\n");
}
}
I have tested the Server with Telnet and the messages a going out as they should, so im almost certain, that the problem somewhere in the client code. I have also tried using a DataInputStream instead of a BufferedReader, but it gives me the same results. Also I don't get any Exeptions.
I have these Permissions in my AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Upvotes: 0
Views: 634
Reputation: 11942
readLine()
blocks until there is a full line (terminated by either \r\n
or \n
) received in the underlying buffer (or the end of the steam has been reached). So unless your server is terminating the data with a linebreak, your program will not print anything. Other than an Exception when the socket times out of course.
Upvotes: 3