• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

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