29
Oct
PrintStream ps; String alias; sClientThread(Socket s, sClientGroup p)
PrintStream ps; String alias; sClientThread(Socket s, sClientGroup p) { /* called by parent */ theSock = s; parent = p; } The run( ) Method So far, we haven t done too much. Just make sure you understand what each of the global variables will be used for. (You may want to go back to Chapter 8, Implementing a High Score Server on a Network, to review.) Next, let s write the run() method that continually waits for any kind of input from the Socket we are assigned to. If it ever gets some (remember that readLine() blocks), it passes the input to the parent sClientGroup to be handled. Here s what it looks like: public void run() { /* try and create new data streams */ try { dis = new DataInputStream( theSock.getInputStream()); ps = new PrintStream( theSock.getOutputStream()); } catch (Exception e); while (theSock !=null) { String input = null; try { input = dis.readLine().trim(); if(input != null) parent.handleInput(input, this); } catch (Exception e); } } Previous Table of Contents Next
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services
