I'd like to send some data from C++ to Java via TCP.
On Java, I will use ByteBuffer to get receiced data.
When bytebuffer.getInt(), I' like to get int data which is sent on C++.
To do this, how do I convert data on C++.
Convert it into network byte order using htons(), htonl(), etc, and receive it with ByteBuffer or DataInputStream.
Related
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
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.
I want to send the ByteBuffer from FlatBuffers over network to an Android Application.
I tried using echo $builder->sizedByteArray, but then I'm wondering how to deserialize this String.
Note that this bytearray has to be sent in a way suited to binary transmission, not text.
As for deserialization with Java, have you looked here: https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html (make sure you select Java as your language) ? You can use ByteBuffer.wrap with a byte[] you received over the network.
I am using Protocol Buffers for my data and want to store and retrieve this data from Memcached (running on ElastiCache). I am using the MemcachedClient in Java.
I am currently storing data to Memcache using code similiar to this:
memClient.set("keyString", protobufBuilder.build().toByteArray());
But, I am not sure how to get this data from Memcached and convert it back into a Protobuf object.
Any help is really appreciated.
I figured it out.
I simply typecasted the data I get from MemcachedCleint to byte[] and gave it as input to the pasreFrom method of my Protobuf object.
Ok, just a simple question, I would like to send a object via java and obj-c. Is this possible to do so? Or I need to change the object to string or something first, and convert it back in to the receive side? Thanks.
It is possible to send a serialised Java object to objective C over a socket, but recovering it is difficult since you'd need to write a library to parse the binary data stream. It's possible someone has already written such a library.
It's easier to send objects encoded in JSON or XML, or with Google protocol buffers.
I would like to send a object via java and obj-c
This is the classic problem of communication between different systems/languages.
The solution has always been XML (usually SOAP which is not my taste) and nowadays the options #Joni mentions in his answer
I'm working on a network in which my python script will communicate with my java application. The python script is passing a DataPacket (just a packet that holds some strings and a little other data) to the java server for processing. I know how to pack the information into a byte array, but how do I unpack it to be used as strings? What I've got so far is I have to parse the arrays of data in the packet and send it in bits and pieces. Is this the only way to do this? Can I use ByteInputStream and if so how?
thanks
~Aedon
I'm not sure that what you're doing is quite right, in that you're fragmenting your strings into separate packets. This could cause problems with multibyte strings.
However, you may wish to check out ByteArrayOutputStream. You can write into this, then convert to a String using toString(enc), where enc is the encoding you've used in your Python to convert your strings into bytes in the first place.
Looking at your comment below, it appears you need some means to serialise in Python and deserialise in Java. Leaving aside solutions like XML serialisation, have you looked at possible solutions like Google Protocol Buffers ?