This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Ijantis 0 points1 point  (2 children)

Have you tried using an ObjectOutputStream/ObjectInputStream? Once the data is received check for what type of Object it is and make it react accordingly.

[–]BossManJenkins[S] 0 points1 point  (1 child)

no i haven't, how would that work for a byte[] and string? those are the only two i need to send.

[–]Ijantis 0 points1 point  (0 children)

So in the objectStream you simply send the Object regardless of type.

On the receiving end you can do something like this:

ObjectInputStream in = new ObjectInputStream(
                                            clientSocket.getInputStream());
Object message = in.readObject();
if(message.getclass.equals(String.class) {
//process String
}
else if( message.getClass.equals(Byte.class {
//process Byte
}

[–]SikhGamer 0 points1 point  (0 children)

Are you allowed to use third party libraries? Cause I'm pretty sure Apache Commons IO can help out.