Cobbles
Cobbles

Reputation: 1808

Android TCP server

I am trying to send a simple textual message to my android phone from my computer. The phone is on the same WiFi network and I am using the tutorial here for the android server. When it receives a connection, I log the message like this:

String read;
Log.i("COB", "test log");
while((read = input.readLine()) != null) {
     Log.i("COB", read);
}

In the logcat in android studio, it prints me the date and time but not the message it seems:

06-25 09:55:12.213    9573-9648/cob.vivid.app I/COB﹕ test log
06-25 09:55:12.213    9573-9648/cob.vivid.app I/COB﹕ [ 06-25 09:55:12.424  1025: 1079 D/WifiStateMachine ]

I am using ncat for windows and I type the following in:

echo messageTest & echo. | ncat {IP ADDRESS} {PORT}

Obviously I use the actual ip and port.

I know that the connection worked because as soon as I enter the ncat command it prints out the logs, but I don't understand why it isn't printing the message as well. Also, what is the 1025: 1079?

Upvotes: 0

Views: 290

Answers (2)

Cobbles
Cobbles

Reputation: 1808

I have fixed it by removing the EOL character & echo..

If someone could explain this solution, then that would be great!

Upvotes: 0

Václav Hodek
Václav Hodek

Reputation: 668

You must send EOL character. Without it, the line is not completed and readLine will not return it.

Also, you take a look at NanoHTTPD which is HTTP server implementation that works smooth on Android and so you have not to do all the work from the scratch.

Upvotes: 1

Related Questions