views:

148

answers:

1

I need to communicate between a Java app (desktop) and an iOS app. I've decided to use AsyncSocket on the iPhone side (and I've gotten data sending to work). For this question, I'm just running the EchoServer demo app on OSX 10.6.4. Source code is here.

Here's my Java code, boiled-down:

    Socket echoSocket = new Socket("192.168.0.102", 8085);
    PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
    out.println("hello there!");
    out.flush();

This works and the "hello there!" shows up on a TCP Monitor.

On the EchoServer, the output is just

           Accepted client 192.168.0.102:4960

So I know they're talking but I cannot get the data!

Edit: On the Java side (with more code), I do receive the Welcome to the "AsyncSocket Echo Server" message.

Edit: If I browse to the server it works perfectly, so the problem is in my Java code. What else do I need to do for a complete write to a socket correctly?

+2  A: 

I think this is a good clue, taken from that demo's AppController.m:

[sock readDataToData:[AsyncSocket CRLFData] withTimeout:READ_TIMEOUT tag:0];

Looks like it will read a line that ends with a CR and LF. So what you might need to do on the Java side is this:

out.print("hello, there\r\n");

Or probably the same:

out.println("hello, there\r");
St3fan
Thanks, I figured this out with no connection on a train a few hours again. I was about to delete the question, but since your answer is here and right....
Yar
@St3fan, the correct answer is that you NEED `\r\n\r\n`... I've tried all other combinations. I don't exactly understand this, but....
Yar