How do you send a User defined class object over a tcp/ip network connection in java?
-
11-11-2019 - |
سؤال
This is an example of a user defined class I'd like to send from a client application to a server application:
class dataStruct implements Serializable{
byte data;
int messageNum;
public void setData(byte datum, int messageNumber){
data=datum;
messageNum=messageNumber;
}
}
How do you send a user defined class over a tcp/ip connection in java?
What types of streams can I use to accomplish this (if I'm sending more than just text)?
Can I pass a full object via a socket stream, or will I always have to cast it after it has been passed via a stream?
I'm writing a server/client application, and I've only been able to find tutorials with examples of primitive types or strings being passed over a network connection - not user defined types.
Your help and direction are greatly appreciated.
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow