I am sending a object through socket using serialization.The issue is
When I send it over a socket(socket.getOutputStream) and read on the server side ,it gives me java.IO.InvalidClassException.
However if I write in a file and then deserialize it in the same class, in which serialization was done,it works fine
Does this happen that sending object using socket causes errors
Even if I use to deserilaize the file which I created ,it is giving me java.IO.InvalidClassException.
I am using the same jar on the either side of socket.The difference is tthat at client side I am running thru eclipse so using jar in build path and ion server side I have kept the extracted folder from jar and placed in the current directory
If the class files on both sides are exactly the same you shouldn't get this error. It only occurs because the class files have different serialVersionUID values. This can easily occur if you add an extra field or method. You can prevent this error in two ways:
1) make sure that both sides really do have the exact same class files.
2) define an explicit private static final long serialVersionUID. Once you've defined all the fields, you can let Eclipse generate one for you. After that you can add, remove and change methods all you want, as long as the fields stay the same.
There are also tricks to be able to handle fields that are added or removed, but you really shouldn't use instances of different versions of the class.