JAVA实现tftp服务端(四)-- WRQ

作者在 2007-05-05 02:17:00 发布以下内容

tftpClientAgent.java
=====================================

    public void WRQ() {
        int ntimeout = this.m_MAX_nTimeOut;
        try {
            short nblock = 0;
            //send the #0 block ACK to start the transfer
            this.SendACK(nblock++);
           
            //wait for the data packet
            while (ntimeout > 0) {
                DatagramPacket dp;
                dp = this.waitForData();
                //dp = new DatagramPacket(buf, 516);
                if (dp == null) {
                    //this.SendERROR((short)0, "超时了,连接被服务器断开 ...");
                    //System.out.println("debug: tftpClientagent.WRQ() --> 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: ip or port error ...");
                        ntimeout--;
                    } else {    //right ip and port
                        //get the opcode
                        DataInputStream din = new DataInputStream(new ByteArrayInputStream(dp.getData()));
                        int opcode = din.readShort();
                        //System.out.println("debug: the opcode is " + opcode

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