objectinputstream - java initializing variable for stream in/out -


i have problem below code. not clear how can initialize variables of in/out.

during creation of object program hangs when in constructor. hangs @ line of this.inobjects = new objectin.......... create in/out objects once read , write on input/output, strings , objects calling them in methods , applying read write etc etc

where going wrong? possible not receiving data hangs? shouldn't, right?

public class pokerclient  {     private pokerclientgui gui;     private socket clientsocket;     private datainputstream in;     private dataoutputstream output;     private objectinputstream inobjects;     private objectoutputstream outobjects;     private hand hand;      //constructor     public pokerclient()     {         try         {             this.gui= gui;             this.clientsocket = new socket("localhost", 4444);             this.in = new datainputstream(this.clientsocket.getinputstream());             this.inobjects = new objectinputstream(this.clientsocket.getinputstream());             this.output = new dataoutputstream(this.clientsocket.getoutputstream());             this.outobjects = new objectoutputstream(this.clientsocket.getoutputstream());         }         catch (exception e)         {         } } 

you should create object output stream first , flush it. should never wrap same stream 2 different ways. never catch exception , ignore unless having errors , no way determine has gone wrong. don't assign field itself, won't useful, confuse people.

public class pokerclient {   private final pokerclientgui gui;   private final socket clientsocket;   private final objectoutputstream outobjects;   private final objectinputstream inobjects;    public pokerclient(pokerclientgui gui) throws ioexception {     this.gui = gui;     clientsocket = new socket("localhost", 4444);     outobjects = new objectoutputstream(clientsocket.getoutputstream());     outobjects.flush();     inobjects = new objectinputstream(clientsocket.getinputstream());   } } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -