问题描述
- JAVA TCP通信,客户端给服务器发送java对象时报错
-
我在做JAVA TCP 编程时,我想实现客户端A与客户端B之间通过服务器C来通信,但是我通过客户端A给服务器发送消息时,我传送的是一个java对象MsgPackage类对象,我通过ObjectOutputStream.writeObject来传送,但是服务器去读取这个对象时报错了,没有能正确读取到客户端发送过来的对象,请各位大神指教一下。错误的消息是这样:
java.lang.ClassNotFoundException: com.client.MsgPackage
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at com.server.ProcRequestThread.run(Server.java:79)
at java.lang.Thread.run(Thread.java:619)
时间: 2024-12-31 02:37:50