views:

711

answers:

3

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.

+2  A: 

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();
Björn
+3  A: 

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)

David Zaslavsky
Sorry could you be more technical by translating the answer you send into code or pseudocode please?
efe
A: 

using

ArrayList a=new ArrayList(n)//n represents size

or

List a=new List()

we can send a to server

KaliRagavendran