im trying to write hashtable between sockets in java
but getting this error :
Error : writing aborted; java.io.NotSerializableException: java.net.Socket
How i can write
EDITED :
socktmp= mainSocket.accept();
rdr= new BufferedReader( new InputStreamReader(socktmp.getInputStream()));
String t="";
String name=rdr.readLine();
//rdr.close();
LstClient.AddClient(name, socktmp);
objwriter = new ObjectOutputStream(socktmp.getOutputStream());
objwriter.writeObject(LstClient.clients);
objwriter.flush();
objwriter.close();
You can’t serialise a Socket. You can only serialize HashMaps of objects which are Serializable. Check you are not adding any anonymous or nested classes with implicit references to an Object which holds a Socket.
BTW: Don’t use Hashtable if you can avoid it. Use
HashMap or LinkedHashMap or ConcurrentHashMap instead.