0

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?

Community
  • 1
  • 1
Cobbles
  • 1,528
  • 15
  • 31

2 Answers2

1

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.

Václav Hodek
  • 548
  • 3
  • 9
  • Thanks! What character should I send? Like \n or something? What do I put at the end of the ncat command? – Cobbles Jun 25 '14 at 11:18
  • You use `readLine()`. This function reads text up to the first newline character `"\n"` encountered. So you have to send an `"\n"` at the end of every `line`. You cannot just type that in as it only works in this way when you add it programmatically. Find out how you can type it in as special character. But.... maybe it is added automatically. I would think so... Just start echoing some simple texts... – greenapps Jun 25 '14 at 12:56
  • Try to echo some text file with few lines. And yes, it's \n character. – Václav Hodek Jun 25 '14 at 17:24
  • I tried ctrl-z at the end of the message and also the \n character, but it still does not signal the end of line. When I use ctrl-z, I get no output. What character can I use in command prompt to signal the end of line? Thanks – Cobbles Jun 25 '14 at 18:52
  • As per this post (http://stackoverflow.com/questions/132799/how-can-you-echo-a-newline-in-batch-files), I am already adding the new line when I type `& echo.` Why does this not work? – Cobbles Jun 25 '14 at 18:55
  • 1
    I think you mean to say carriage-return character, not EOF. – selbie Jun 26 '14 at 03:51
0

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

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

Cobbles
  • 1,528
  • 15
  • 31