Java - Send array over socket

ARedGuitar

n00b
Joined
Oct 16, 2006
Messages
49
I have a server program and a client program. Both work fine on their own. However, there are a couple of lists on the server that I'd like to send to the client. Is there any way to send a String array or an int array to the client?
 
Well, I never knew those would work for networks. So i would send the Array contents with writeObject()?

i.e.
Code:
for(String s : strArray)
 ObjectOutputStream.writeObject(s);
 
With ObjectOutputStream, you can just write the entire String array with a single call. If you use DataOutputStream, you'd have to write a length value first and then each element of the array. The length value would be needed so that the reader would know how many elements to expect. The catch with ObjectOutputStream is that the objects being written need to be serializable, but that's not a concern for a String array.
 
Back
Top