private Socket soc = null; // Client socket. private DataOutputStream out = null; // Data writer (send to Server). private DataInputStream in = null; // Data reader (received from Server). : this.soc = new Socket(this.machine.ipadres,port); this.out = new DataOutputStream(this.soc.getOutputStream()); this.in = new DataInputStream(this.soc.getInputStream()); : private void loginLoop(Machine machine) throws IOException{ StringBuffer sb = new StringBuffer(); int c0; while(true){ c0 = this.in.readUnsignedByte(); if (c0 == 255){ // IAC ? recvIAC(c0); // IAC送受信 }else{ // Normal charaters. Dump onto tty. sb.append((char)c0); if (machine.loginprompt.length()>0){ if (sb.toString().endsWith(machine.loginprompt)){ this.out.writeBytes(machine.loginID+"\r\n"); this.out.flush(); } } if (sb.toString().endsWith(machine.passwdprompt)){ this.out.writeBytes(machine.password+"\r\n"); this.out.flush(); break; } if(sb.toString().endsWith(machine.prompt)){ break; // 既にログイン済みなら次へ } } } } /** * IAC受信 */ private void recvIAC(int c0) throws IOException { int c1,c2,c3=0; c1 = c0; c1 = this.in.readUnsignedByte (); if (c1 >= 251 && c1 <= 254) { // WILL / DO c2 = in.readUnsignedByte(); switch(c1){ case 251: // WILL case 252: // WON'T c3 = 254; // DON'T break; case 253: // DO case 254: c3 = 252; // WON'T break; } this.out.write(255); // IAC this.out.write(c3); // DON'T/WON'T this.out.write(c2); // option this.out.flush(); } }