JAVA实现tftp服务端(三)-- RRQ

作者在 2007-05-04 04:33:00 发布以下内容

tftpClientAgent.java
=====================================
    public void RRQ() {
        int ntimeout = this.m_MAX_nTimeOut;
        try {
            short nblock = 1;
            //send the #0 block ACK to start the transfer
            if (!this.SendFile(nblock, this.m_filename, this.m_mode)) {
                this.SendERROR((short)0, "无法读取文件");
                return ;
            }
           
            //wait for the ACK packet
            while (ntimeout > 0) {
                DatagramPacket dp;
                dp = this.waitForData();
               
                if (dp == null) {
                    //this.SendERROR((short)0, "超时了,连接被服务器断开 ...");
                    //System.out.println("debug: tftpClientagent.RRQ() --> timeout: " + ntimeout);
                    ntimeout--;
                } else {
                    //ok, get a packet, check the ip and port
                    if (!((dp.getAddress().equals(this.m_ClientAddress))
                            && (dp.getPort() == this.m_ClientPort))) {
                        //ip or port has a mistake
                        //this.SendERROR((short)0, "我不认识你");
                        //System.out.println("debug: RRQ() --> ip or port error ...");
                        ntimeout--;
                    } else {    //right ip and port
                        //get the opcode
                        DataInputStream din = new DataInputStream(new ByteArrayInputStream(dp.getData()));
       &nb

JAVA | 阅读 1503 次
文章评论,共0条
游客请输入验证码