How to send FlatBuffers ByteBuffer over network? - java

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.

Related

How to convert data sending data through TCP from C++ to Java

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.

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
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.

Is this possible to send a java object to an obj-c, and obj-c to java via socket?

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

Passing strings[]'s as byte[]

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 ?

How to Convert ActionScriptObject to ByteArray?

The coding language is Java.
I have a ByteArray embedded in ActionScriptObject.(http://smartfoxserver.com/'>Smartfox Server)
I want to convert it into ByteArray.
The idea is to save it as an image.
This a sequel to the post --> Convert Byte Array from Action Script to Image in Java and save it
Have tried http://www.javafaq.nu/java-article236.html'>this method
It failed with the
java.io.NotSerializable Exception
Regards,
naveenj
The NotSerializableException is because the ActionScriptObject does not implement Serializable.
The ActionScriptObject does not support byte arrays. This is according to information found on the SmartFox Server forum. This probably means that when it creates the Java object that represents your ActionScript object, it does not copy the "arr" property at all!
To transfer the image data to the server you will have to use a network socket and write the data down the wire.
Reading the docs for Smartfox Server, there is a SocketLoader tutorial in chapter 8.17 which should allow you to transmit the image data to the server. http://www.smartfoxserver.com/docs/index.htm?http://www.smartfoxserver.com/docs/docPages/tutorials_pro/17_socketFileLoader/index.htm
Have you tried with JBoss Serialization? http://www.jboss.org/serialization
Regards.

Categories