javaphpdataoutputstream

PHP read input stream from Java DataOutputStream?


For a while, I've been working on a Java client that sends level information to save online. I have managed using printwriter, but it is really inefficient, and a simple 300KB level turns out to be 3MB after the transfer, and is rather slow.

I know people have used "file_get_contents("php://input")", such as in receive output from java DataOutputStream in a php page, but I am not sure how to receive specific data from:

//phpsend is the DataOutputStream using POST (java)
phpsend.writeUTF(username);
phpsend.writeUTF(verificationId);
phpsend.writeInt(levelsize);
phpsend.write(level); //level has been converted to a byte array

how would I read each separate write? I know Java had DataInputStream, which had all the corresponding read functions, but how would I do that in PHP? I've heard of "Sockets" and "SOAPClient", but I could not find any information that I could use


Solution

  • So I have found that

    file_get_contents("php://input")
    

    seems to do the what I want. Simply assign its result to a variable

    $data = file_get_contents("php://input");
    

    and the $data get all Java sent.