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

📄 wapptr.java~351~

📁 jwap 协议 udp 可以用于手机通讯
💻 JAVA~351~
📖 第 1 页 / 共 5 页
字号:
    }

    /**
     * ReadJwapConf
     */
    public boolean ReadJwapConf() {
        boolean ret = false;
        FileWork m_fw = new FileWork();
        Vector tempVector = new Vector();
        try {
            gwAddr = InetAddress.getByName("10.0.0.172");
        } catch (UnknownHostException ex1) {
        }
        gwPort = 9201;
        String oneline = new String("");
        try {
            m_fw.FW_ReadFile("Itouch.conf", tempVector);
            for (int i = 0; i < tempVector.size(); i++) {
                oneline = tempVector.elementAt(i).toString();
                String[] StrArry = oneline.split("\\|");
                if (StrArry[0].equals("0000")) {
                    int c = StrArry[1].indexOf(':');
                    if (c > 0) {
                        gwAddr = InetAddress.getByName(StrArry[1].substring(0,
                                c));
                        gwPort = Integer.parseInt(StrArry[1].substring(c + 1));
                    } else {
                        gwAddr = InetAddress.getByName(StrArry[1]);
                        gwPort = 9201;
                    }
                    ret = true;
                } else if (StrArry[0].equals("2001")) {
                    AgentName = StrArry[1];
                    //xhtml_wml=1;
                    //String[] uaArry = oneline.split("\\:");
                    int pos = AgentName.lastIndexOf(":");
                    if (pos >= 0) {
                        String str1 = AgentName.substring(0, pos);
                        String str2 = AgentName.substring(pos + 1, pos + 2);
                        AgentName = str1;
                        if (str2.equals("2")) {
                            xhtml_wml = 1;
                        } else {
                            xhtml_wml = 0;
                        }
                    }
                    ret = true;
                }

            }
        } catch (IOException ex) {
            ex.printStackTrace();
            ret = false;
        }
        return ret;
    }

    /**
     * Post_Req
     *
     * @param m_url String
     */
    public boolean Req(String m_url, String LogFileName) {
        boolean ret = true;
        String url = m_url;
        long tc = DEFAULT_CONNECT_TIMEOUT;
        long tx = DEFAULT_EXEC_TIMEOUT;
        int RetCode = 0;
        long BegMillisTims = 0;
        long EndMillisTims = 0;

        if (m_url.equals("")) {
            return false;
        }
        int mIndex = 0;
        String TempUrl = url;
        String TempUrl2 = "";
        if (downmms == 1) {
            FileType = "mms";
        } else {
            mIndex = TempUrl.lastIndexOf(".");
            if (mIndex != -1) {

                String tempFile1ow = TempUrl.substring(mIndex + 1);
                String tempFile = tempFile1ow.toUpperCase();
                if (tempFile.equals("GIF") || tempFile.equals("JPG") ||
                    tempFile.equals("BMP") ||
                    tempFile.equals("WBMP") || tempFile.equals("PNG") ||
                    tempFile.equals("AMR") || tempFile.equals("WAV") ||
                    tempFile.equals("MID") || tempFile.equals("MP3") ||
                    tempFile.equals("RM") ||
                    tempFile.equals("JAR") || tempFile.equals("WAR") ||
                    tempFile.equals("JAD")) {
                    FileType = tempFile;
                } else {
                    int ps = tempFile.indexOf("JAR");
                    int ps1 = tempFile.indexOf("WAR");
                    int ps2 = tempFile.indexOf("JAD");
                    if (ps >= 0) {
                        FileType = "JAR";
                    } else if (ps1 >= 0) {
                        FileType = "WAR";
                    } else if (ps2 >= 0) {
                        FileType = "JAD";
                    } else {
                    }

                }

            } else {
                FileType = "null";
            }
        }

        Request request = null;
        request = new GetRequest(url);

        try {

            //开始连接网关
            CWTPStatue.SetType(0);
            BegMillisTims = System.currentTimeMillis();
            LogStr[0] = Long.toString(BegMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(BegMillisTims).substring(10);
            LogStr[2] = "0";
            LogStr[9] = m_url;
            WriteLog(LogFileName);
            if (xhtml_wml == 1) {
                RetCode = connect_http(tc);
            } else {
                RetCode = connect(tc);
            }

            //RetCode=connect(tc);
            EndMillisTims = System.currentTimeMillis();
            LogStr[0] = Long.toString(EndMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(EndMillisTims).substring(10);
            LogStr[2] = Integer.toString(RetCode);
            LogStr[7] = Long.toString(EndMillisTims - BegMillisTims);
            LogStr[8] = Integer.toString(CWTPStatue.GetResultState());
            WriteLog(LogFileName);
            if (RetCode == 7) {
                return false;
            }
            //开始下载
            CWTPStatue.SetType(1);
            BegMillisTims = System.currentTimeMillis();
            LogStr[0] = Long.toString(BegMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(BegMillisTims).substring(10);
            if (downmms == 1) {
                LogStr[2] = "820";
            } else {
                LogStr[2] = "100";
            }
            LogStr[7] = "0";
            LogStr[8] = "0";
            WriteLog(LogFileName);
            markflg.Setval(1);
            Response response = null;
            int xhtm_ret = -1;
            if (xhtml_wml == 1) {
                xhtm_ret = execute_http(request, tx);
            } else {
                response = execute(request, tx);
            }

            //Response response = execute(request, tx);
            if (xhtml_wml == 1) {
                EndMillisTims = downtime;
            } else {
                EndMillisTims = System.currentTimeMillis();
            }
            LogStr[0] = Long.toString(EndMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(EndMillisTims).substring(10);
            LogStr[7] = Long.toString(EndMillisTims - BegMillisTims);
            if (xhtml_wml == 1) {

                if (xhtm_ret == -1) {
                    LogStr[8] = Integer.toString(50);
                    if (downmms == 1) {
                        LogStr[2] = "827";
                    } else {
                        LogStr[2] = "107";
                    }

                    System.out.println("下载失败");
                } else {
                    LogStr[8] = Integer.toString(32);
                    if (downmms == 1) {
                        LogStr[2] = "825";
                    } else {
                        LogStr[2] = "105";
                    }

                    //LogStr[2]="105";
                    ret = true;
                    System.out.println("下载成功");
                    downloadflg = 0;
                }

            } else {
                LogStr[8] = Integer.toString(CWTPStatue.GetResultState());
                if (response == null || downloadflg == 0) {
                    if (downmms == 1) {
                        LogStr[2] = "827";
                    } else {
                        LogStr[2] = "107";
                    }

                    System.out.println("下载失败");
                } else {
                    if (downmms == 1) {
                        LogStr[2] = "825";
                    } else {
                        LogStr[2] = "105";
                    }

                    //LogStr[2]="105";
                    ret = true;
                    System.out.println("下载成功");
                    downloadflg = 0;
                }
            }
            markflg.Setval(0);
            WriteLog(LogFileName);

        } catch (IllegalStateException ex) {
            System.out.println(ex.getMessage());
        } catch (SocketException ex) {
            System.out.println(ex.getMessage());
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage());
            /** @todo Handle this exception */
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
            /** @todo Handle this exception */
        }

        //finally {
        if (xhtml_wml == 1) {
            http_disconnect();
        } else {
            // disconnect();
        }
        //}

        return ret;
    }

    public boolean Post(String m_url, String postfile, String LogFileName) {
        boolean ret = false;

        String userAgent = null;
        String output = null;
        String contentType = "application/vnd.wap.mms-message";
        String input = postfile;
        String url = m_url;
        int lp = CWTPSocket.DEFAULT_PORT;
        long tc = DEFAULT_CONNECT_TIMEOUT;
        long tx = DEFAULT_EXEC_TIMEOUT;
        int RetCode = 0;
        long BegMillisTims = 0;
        long EndMillisTims = 0;
        //xhtml_wml = 1;
        int xhtm_ret = -1;

        if (m_url.equals("")) {
            return false;
        }

        Request request = null;

        if (contentType == null) {
            System.err.println("Warning: no content-type specified, assuming " +
                               DEFAULT_CONTENT_TYPE);
            contentType = DEFAULT_CONTENT_TYPE;
        }
        byte[] postData = null;
        try {
            postData = readPostData(input);
        } catch (IOException ex1) {
        }
        Sendflg = 1;
        PostRequest preq = new PostRequest(url);
        request = preq;
        preq.setContentType(contentType);
        preq.setRequestBody(postData);

        try {

            //开始连接网关
            CWTPStatue.SetType(0);
            BegMillisTims = System.currentTimeMillis();
            LogStr[0] = Long.toString(BegMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(BegMillisTims).substring(10);
            LogStr[2] = "0";
            LogStr[9] = m_url;
            WriteLog(LogFileName);
            if (xhtml_wml == 1) {
                RetCode = connect_http(tc);
            } else {
                RetCode = connect(tc);
            }

            //RetCode=connect(tc);
            EndMillisTims = System.currentTimeMillis();
            LogStr[0] = Long.toString(EndMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(EndMillisTims).substring(10);
            LogStr[2] = Integer.toString(RetCode);
            LogStr[7] = Long.toString(EndMillisTims - BegMillisTims);
            LogStr[8] = Integer.toString(CWTPStatue.GetResultState());
            WriteLog(LogFileName);
            if (RetCode == 7) {
                return false;
            }

            //开始下载
            CWTPStatue.SetType(1);
            BegMillisTims = System.currentTimeMillis();
            LogStr[0] = Long.toString(BegMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(BegMillisTims).substring(10);
            LogStr[2] = "820";
            LogStr[7] = "0";
            LogStr[8] = "0";
            WriteLog(LogFileName);
            markflg.Setval(1);
            Response response = null;
            if (xhtml_wml == 1) {
                xhtm_ret = execute_http(request, tx);
            } else {
                response = execute(request, tx);
            }

            // Response response = execute(request, tx);

            EndMillisTims = System.currentTimeMillis();
            LogStr[0] = Long.toString(EndMillisTims).substring(0, 10);
            LogStr[1] = Long.toString(EndMillisTims).substring(10);
            LogStr[7] = Long.toString(EndMillisTims - BegMillisTims);

            if (xhtml_wml == 1) {

                if (xhtm_ret == -1) {
                    LogStr[8] = Integer.toString(50);
                    LogStr[2] = "827";
                    System.out.println("发送失败");
                } else {
                    LogStr[8] = Integer.toString(32);
                    LogStr[2] = "825";
                    ret = true;
                    System.out.println("发送成功");
                }

            } else {
                LogStr[8] = Integer.toString(CWTPStatue.GetResultState());
                if (response == null) {
                    LogStr[2] = "827";
                    System.out.println("发送失败");
                } else {
                    LogStr[2] = "825";
                    ret = true;
                    System.out.println("发送成功");
                }

            }

⌨️ 快捷键说明

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