views:

44

answers:

2

I'm experiencing a bizarre problem with sockets between a Java Knopflerfish client bundle and a PHP (CLI, not web) server.

The client/server pair work fine when both are located on the localhost, and all data is transmitted successfully. However, when the Java client exists on a different machine, connections to the server are successful, but no data is received by the PHP script. Packet analysis confirms that the data sent by the Java client is received on by the server - PHP just seems to have problems getting its hands on it.

As a further note, I've done some tests with telnet as the client. The PHP server script receives all data fine from any host. This leads me to believe that the problem has something to do with the way java is setting up the socket or that there is some networking issue that I'm not familiar with. Any thoughts would be appreciated. Can post code samples if desired.

A: 

You probably forgot to flush the buffers on the client side. telnet does a flush for every line, so that would explain why it works.

Aaron Digulla
I suspected that might be the issue also, but confirmed, and I already do a flush on the client.
Mark Griffin
Additionally, if I weren't flushing, I don't think I'd be receiving packets on the server whatsoever (right?) - I can see them in wireshark.
Mark Griffin
A: 

Turns out it was a race condition. If I sleep for a few milliseconds after receiving a connection and before doing a socket_read, it does the trick nicely.

Mark Griffin