⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 telnetprotocolhandler.java

📁 The Javatm Telnet Application/Applet 很好用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  public int negotiate(byte nbuf[])  throws IOException  {    byte sbbuf[] = new byte[tempbuf.length];    int count = tempbuf.length;    byte[] buf = tempbuf;    byte sendbuf[] = new byte[3];    byte b,reply;    int  sbcount = 0;    int boffset = 0, noffset = 0;    boolean dobreak = false;    if (count == 0) 	// buffer is empty.      return -1;    while(!dobreak && (boffset < count) && (noffset < nbuf.length)) {      b=buf[boffset++];      // of course, byte is a signed entity (-128 -> 127)      // but apparently the SGI Netscape 3.0 doesn't seem      // to care and provides happily values up to 255      if (b>=128)        b=(byte)((int)b-256);      if(debug > 2) {        Byte B = new Byte(b);        System.err.print("byte: " + B.intValue()+ " ");      }      switch (neg_state) {      case STATE_DATA:        if (b==IAC) {          neg_state = STATE_IAC;	  dobreak = true; // leave the loop so we can sync.        } else           nbuf[noffset++]=b;        break;      case STATE_IAC:        switch (b) {        case IAC:          if(debug > 2) System.err.print("IAC ");          neg_state = STATE_DATA;          nbuf[noffset++]=IAC;          break;        case WILL:          if(debug > 2) System.err.print("WILL ");          neg_state = STATE_IACWILL;          break;        case WONT:          if(debug > 2) System.err.print("WONT ");          neg_state = STATE_IACWONT;          break;        case DONT:          if(debug > 2) System.err.print("DONT ");          neg_state = STATE_IACDONT;          break;        case DO:          if(debug > 2) System.err.print("DO ");          neg_state = STATE_IACDO;          break;        case EOR:          if(debug > 1) System.err.print("EOR ");  	  notifyEndOfRecord();	  dobreak = true; // leave the loop so we can sync.          neg_state = STATE_DATA;          break;        case SB:          if(debug > 2) System.err.print("SB ");          neg_state = STATE_IACSB;          sbcount = 0;          break;        default:          if(debug > 2) System.err.print("<UNKNOWN "+b+" > ");          neg_state = STATE_DATA;          break;        }        break;      case STATE_IACWILL:        switch(b) {        case TELOPT_ECHO:          if(debug > 2) System.err.println("ECHO");          reply = DO;          setLocalEcho(false);          break;        case TELOPT_SGA:          if(debug > 2) System.err.println("SGA");          reply = DO;          break;        case TELOPT_EOR:          if(debug > 2) System.err.println("EOR");          reply = DO;          break;        case TELOPT_BINARY:          if(debug > 2) System.err.println("BINARY");          reply = DO;          break;        default:          if(debug > 2) System.err.println("<UNKNOWN,"+b+">");          reply = DONT;          break;        }        if(debug > 1) System.err.println("<"+b+", WILL ="+WILL+">");        if (reply != sentDX[b+128] || WILL != receivedWX[b+128]) {          sendbuf[0]=IAC;          sendbuf[1]=reply;          sendbuf[2]=b;          write(sendbuf);          sentDX[b+128] = reply;          receivedWX[b+128] = WILL;        }        neg_state = STATE_DATA;        break;      case STATE_IACWONT:        switch(b) {        case TELOPT_ECHO:          if(debug > 2) System.err.println("ECHO");          setLocalEcho(true);          reply = DONT;          break;        case TELOPT_SGA:          if(debug > 2) System.err.println("SGA");          reply = DONT;          break;        case TELOPT_EOR:          if(debug > 2) System.err.println("EOR");          reply = DONT;          break;        case TELOPT_BINARY:          if(debug > 2) System.err.println("BINARY");          reply = DONT;          break;        default:          if(debug > 2) System.err.println("<UNKNOWN,"+b+">");          reply = DONT;          break;        }        if(reply != sentDX[b+128] || WONT != receivedWX[b+128]) {          sendbuf[0]=IAC;          sendbuf[1]=reply;          sendbuf[2]=b;          write(sendbuf);          sentDX[b+128] = reply;          receivedWX[b+128] = WILL;        }        neg_state = STATE_DATA;        break;      case STATE_IACDO:        switch (b) {        case TELOPT_ECHO:          if(debug > 2) System.err.println("ECHO");          reply = WILL;          setLocalEcho(true);          break;        case TELOPT_SGA:          if(debug > 2) System.err.println("SGA");          reply = WILL;          break;        case TELOPT_TTYPE:          if(debug > 2) System.err.println("TTYPE");          reply = WILL;          break;        case TELOPT_BINARY:          if(debug > 2) System.err.println("BINARY");          reply = WILL;          break;        case TELOPT_NAWS:          if(debug > 2) System.err.println("NAWS");          Dimension size = getWindowSize();          receivedDX[b] = DO;          if(size == null) {            // this shouldn't happen            write(IAC);            write(WONT);            write(TELOPT_NAWS);            reply = WONT;            sentWX[b] = WONT;            break;          }          reply = WILL;          sentWX[b] = WILL;          sendbuf[0]=IAC;          sendbuf[1]=WILL;          sendbuf[2]=TELOPT_NAWS;          write(sendbuf);          write(IAC);write(SB);write(TELOPT_NAWS);          write((byte) (size.width >> 8));          write((byte) (size.width & 0xff));          write((byte) (size.height >> 8));          write((byte) (size.height & 0xff));          write(IAC);write(SE);          break;        default:          if(debug > 2) System.err.println("<UNKNOWN,"+b+">");          reply = WONT;          break;        }        if(reply != sentWX[128+b] || DO != receivedDX[128+b]) {          sendbuf[0]=IAC;          sendbuf[1]=reply;          sendbuf[2]=b;          write(sendbuf);          sentWX[b+128] = reply;          receivedDX[b+128] = DO;        }        neg_state = STATE_DATA;        break;      case STATE_IACDONT:        switch (b) {        case TELOPT_ECHO:          if(debug > 2) System.err.println("ECHO");          reply = WONT;          setLocalEcho(false);          break;        case TELOPT_SGA:          if(debug > 2) System.err.println("SGA");          reply = WONT;          break;        case TELOPT_NAWS:          if(debug > 2) System.err.println("NAWS");          reply = WONT;          break;        case TELOPT_BINARY:          if(debug > 2) System.err.println("BINARY");          reply = WONT;          break;        default:          if(debug > 2) System.err.println("<UNKNOWN,"+b+">");          reply = WONT;          break;        }        if(reply != sentWX[b+128] || DONT != receivedDX[b+128]) {          write(IAC);write(reply);write(b);          sentWX[b+128] = reply;          receivedDX[b+128] = DONT;        }        neg_state = STATE_DATA;        break;      case STATE_IACSBIAC:        if(debug > 2) System.err.println(""+b+" ");        if (b == IAC) {          sbcount = 0;          current_sb = b;          neg_state = STATE_IACSBDATA;        } else {          System.err.println("(bad) "+b+" ");          neg_state = STATE_DATA;        }        break;      case STATE_IACSB:        if(debug > 2) System.err.println(""+b+" ");        switch (b) {        case IAC:          neg_state = STATE_IACSBIAC;          break;        default:          current_sb = b;          sbcount = 0;          neg_state = STATE_IACSBDATA;          break;        }        break;      case STATE_IACSBDATA:        if (debug > 2) System.err.println(""+b+" ");        switch (b) {        case IAC:          neg_state = STATE_IACSBDATAIAC;          break;        default:          sbbuf[sbcount++] = b;          break;        }        break;      case STATE_IACSBDATAIAC:        if (debug > 2) System.err.println(""+b+" ");        switch (b) {        case IAC:          neg_state = STATE_IACSBDATA;          sbbuf[sbcount++] = IAC;          break;        case SE:          handle_sb(current_sb,sbbuf,sbcount);          current_sb = 0;          neg_state = STATE_DATA;          break;        case SB:          handle_sb(current_sb,sbbuf,sbcount);          neg_state = STATE_IACSB;          break;        default:          neg_state = STATE_DATA;          break;        }        break;      default:        if (debug > 1)           System.err.println("This should not happen: "+neg_state+" ");        neg_state = STATE_DATA;        break;      }    }    // shrink tempbuf to new processed size.    byte[] xb = new byte[count-boffset];    System.arraycopy(tempbuf,boffset,xb,0,count-boffset);    tempbuf = xb;    return noffset;  }  public void inputfeed(byte[] b, int len) {    byte[] xb = new byte[tempbuf.length+len];    System.arraycopy(tempbuf,0,xb,0,tempbuf.length);    System.arraycopy(b,0,xb,tempbuf.length,len);    tempbuf = xb;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -