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.
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();
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)
using
ArrayList a=new ArrayList(n)//n represents size
or
List a=new List()
we can send a to server