java - In android Studio, Can't get Object from Server by ObjectInputStream. -


i'm connecting android app , server in computer using objectinputstream , output stream. used asynctask thread.

firstly, server page wrote in eclipse. used serverthread multithread.

class server {  public server() {     serversocket server;     try {         server = new serversocket(8789);         system.out.println("waiting");         while(true){         socket client=server.accept();         system.out.println("connected");                 objectinputstream ois=new objectinputstream(client.getinputstream());                objectoutputstream oos=new objectoutputstream(client.getoutputstream());              serverthread thread=new serverthread(ois, oos);               new thread(thread).start();                      }      } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();     }    } public static void main(string[] args) {     new server(); }       } 

and serverthread.java

class serverthread implements runnable {       objectinputstream ois;       objectoutputstream oos;       database db=new database();       command c;       boolean exit=false;          public serverthread(objectinputstream ois, objectoutputstream oos) {     this.ois=ois;     this.oos=oos;  }  @override public void run() {     while(!exit){      try {         c=(command)ois.readobject();          int type=c.getcommandvalue();         object []args=c.getargs();         switch(type){          case command.login:             string id=(string)args[0];             string pw=(string)args[1];             system.out.println("id&pw android : "+id+","+pw);             client cli=db.searchone(id, pw);             if(id.equals(cli.getid())&&pw.equals(cli.getpw())){                 system.out.println("login success");                 c.setmessage("success");                 system.out.println("command android : "+c);                 oos.writeobject(c);                 oos.flush();                 system.out.println("well done");              }else{                 system.out.println("로그인 실패");                 c.setmessage("로그인 실패");                 oos.writeobject(c);             } 

break;

   `protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     textview = (textview) findviewbyid(r.id.textview);     button button = (button) findviewbyid(r.id.button);     button button_login=(button) findviewbyid(r.id.login);      button.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {          /*connectthread th=new connectthread();             log.d(tag, "스레드부름");             th.start();*/              backgroundtask bk=new backgroundtask();             bk.execute();         }     });        button_login.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             edittext tf_id_forlogin = (edittext) findviewbyid                    (r.id.tf_id_login);              edittext tf_pw_forlogin = (edittext) findviewbyid(r.id.tf_pw_login);             string id = tf_id_forlogin.gettext().tostring();             string pw = tf_pw_forlogin.gettext().tostring();             command c = new command(command.login);             object args[] = {id, pw};             c.setargs(args);             toast.maketext(getapplicationcontext(), "id pw pc server : " + id + "," + pw + c.tostring(), toast.length_long).show();             try {                 ***log.d(tag, "try login");***                 oos.writeobject(c);                  c = (command) ois.readobject();                 log.d(tag, "received : "+c);                 toast.maketext(getapplicationcontext(), "received : " + c.tostring(), toast.length_long).show();                 if (c.getmessage().equals("success")) {                     toast.maketext(getapplicationcontext(), "로그인 성공했다. ", toast.length_long).show();                 } else {                     toast.maketext(getapplicationcontext(), "로그인 실패했다. ", toast.length_long).show();                 }             } catch (exception e) {                 e.printstacktrace();             }           }     }); 

` finally, android studio's code. can see weel log message ***log.d(tag, "try login");* after that, dosen't apper message logcat. dosen't work of ois.readobject , can't find reason why. no error message appeared.**


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -