I'm having a problem sending a job (an integer array) from client to server in two different packages over a socket connection. Any ideas please?
I can explain further if my question is not clear enough.
I'm having a problem sending a job (an integer array) from client to server in two different packages over a socket connection. Any ideas please?
I can explain further if my question is not clear enough.
To answer the question in your title, I would wrap the SocketOutputStream in a BufferedOutputStream in a DataOutputStream and use the latter's writeInt() method repeatedly. Or you could use ObjectOutputStream in place of DataOutputStream, and serialize the array: objOutStream.writeObject(theArray). To read it in again on the other end, just wrap the SocketInputStream in (1) a DataInputStream and use readInt() repeatedly, or (2) a ObjectInputStream and use readObject().
(If you don't have to interoperate with other languages, Object*Stream is easier on you)
Do you have to send it as an array? It complicates the whole process. Why not wrap it in a Collection or some sort of List? I.e:
ObjectOutputStream oos = new ObjectOutputStream(...);
oos.writeObject(integerCollection);
ObjectInputStream ois = new ObjectInputStream(...);
Collection integerCollection = (Collection)ois.readObject();
What protocol are you using to send this data over your link? You can wrap your array in an object that can be serialized into an output stream.
TCP: Things should be pretty simple in this case. The transport layer will take care of fragmenting your object and getting it right at the other end of the link.
UDP: Things can get a little bit complicated; If the object you are trying to serialize is bigger than the UDP buffers (in terms of bytes) then you might not be able to get the data through. In this situation, you can send your data in chunks that are smaller than the default UDP buffer size.
Regards,