public void run() { try { Scanner scr = new Scanner(sock.getInputStream()); byte[] buf = new byte[2048]; //Small powers of two are reccomended, this seems like a good number int read = 0; while(!shouldStop) this.readMessage(scr); //Possibly mulithread this? } catch(IOException ioe) { //This is to get around the no-exception interface smj.log("Exception in thread: "+ioe); RuntimeException re = new RuntimeException(ioe); re.initCause(ioe); throw re; } } /** * Stops the thread on its next iteration. */ public void signalStop() { this.shouldStop = true; } private void readMessage(Scanner scr) { long majop, minop; //major and minor ops smj.log("Reading message..."); majop = scr.nextByte(); minop = scr.nextByte(); smj.log(String.valueOf(majop)); smj.log(String.valueOf(minop)); if(majop==NetConstants.AVATAR) { if(minop==NetConstants.INITIAL) { String name = scr.next(namePattern); String xin = scr.next(numberPattern); String yin = scr.next(numberPattern); float x = Float.valueOf(xin); float y = Float.valueOf(yin); smj.log("User: "+name+" X: "+x+" Y: "+y); } } }