Java Send custom object via socket Client, Server, LAN -


i want send object (custom class) via socket client server. code:

server:

private class socketserverthread extends thread {      @override     public void run() {         try {             serversocket = new serversocket(socketserverport);              while (true) {                 clientsocket = serversocket.accept();                 objectinputstream inobject = new objectinputstream(                         clientsocket.getinputstream());                 try {                     te xxx = (te) inobject.readobject();                  } catch (classnotfoundexception e) {                     e.printstacktrace();                 }                   //datainputstream datainputstream = new datainputstream(                         //clientsocket.getinputstream());                 //messagefromclient=datainputstream.readutf();          activity.runonuithread(new runnable() {             @override             public void run() {                 //activity.msgfromc.settext(messagefromclient);             }         });     } } 

client:

public client(string aipaddres, int aport, te u) {     addressip = aipaddres;     port = aport;     senduser = u; } protected void doinbackground(void... arg0) {      socket clientsocket = null;      try {          clientsocket = new socket(addressip, port);         objectoutputstream outobject = new objectoutputstream(                 clientsocket.getoutputstream());         outobject.writeobject(senduser);         //dataoutputstream danewyjsciowe = new dataoutputstream(                 //clientsocket.getoutputstream());         //danewyjsciowe.writeutf("czesc!" );      } catch (unknownhostexception e) {         // todo auto-generated catch block         e.printstacktrace();         //response = "unknownhostexception: " + e.tostring();     } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();         //response = "ioexception: " + e.tostring();     } {         if (clientsocket != null) {             try {                 clientsocket.close();              } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }         }     }     return null;  } 

custom class (te.class):

public class te implements serializable { public string message; public te(string m){     message=m; } 

}

when passing simple data i.e. string there no problem. want pass object, there classnotfoundexception @ server. read lot of stacks didnt find answer. u me?


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -