亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cwtpsocket.java~5~

?? jwap 協議 udp 可以用于手機通訊
?? JAVA~5~
字號:
/**
 * JWAP - A Java Implementation of the WAP Protocols
 * Copyright (C) 2001-2004 Niko Bender
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package net.sourceforge.jwap.wtp;

import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.*;
import java.util.Hashtable;

import net.sourceforge.jwap.util.Logger;
import net.sourceforge.jwap.util.Utils;
import net.sourceforge.jwap.wtp.pdu.CWTPAbort;
import net.sourceforge.jwap.wtp.pdu.CWTPAck;
import net.sourceforge.jwap.wtp.pdu.CWTPInvoke;
import net.sourceforge.jwap.wtp.pdu.CWTPPDU;
import net.sourceforge.jwap.wtp.pdu.EWTPCorruptPDUException;


/**
 * This class interfaces to the lower layer, the UDP Layer.
 * We use a DatagramSocket here.<br>
 * Per WSP session (defined by local port + address and remote port + address)
 * we need one object of type CWTPSocket. We may need more than one transaction
 * (CWTPTransaction) per session. CWTPSocket listens in a endless thread
 * for new datagrams on the DatagramSocket. If it gets one, it uses
 * CWTPFactory to decode the PDU. Then it associates the PDU with a transaction
 * by comparing the Transaction Identifier.<br>
 * The constructor is private. Use #getInstance(CWTPTransaction t) to
 * get an object for a specific transaction. This is because we want to check,
 * if there already exists a CWTPManagement for the session the transaction
 * belongs to.<br>
 */
public class CWTPSocket extends Thread
{
    static Logger logger = Logger.getLogger(CWTPSocket.class);

    /** WAP Socket type tcp/udp  */
    public int TcpUdp=0;
    public  int tid=0;
    /** WAP Default client port (49200)  */
    public static final int DEFAULT_PORT = 49200;

    /**
     * the underliing Layer, a DatagramSocket (UDP)
     */
    private DatagramSocket socket=null;

    /**
     * the underliing Layer, a DatagramSocket (TCP)
     */
     private Socket TcpSocket=null;
     DataOutputStream Tcpoutput=null;
     DataInputStream Tcpinput=null;

    /**
     * the upper Layer, modelling the session, WSP
     */
    private IWTPUpperLayer upperLayer;

    // remote port and address
    private int toPort;
    private InetAddress toAddress;

    // Used to synchronize reader-thread with close() method
    private byte[] lock = new byte[0];
    private boolean isRunning;

    /**
     * Holds all transactions belonging to this management entity and
     * their corresponding Transaction IDs wrapped in an Integer
     */
    private Hashtable transactions = new Hashtable();

    public CWTPSocket(InetAddress toAddress, int toPort,
        IWTPUpperLayer upperLayer) throws SocketException {
        this(toAddress, toPort, null, DEFAULT_PORT, upperLayer);
    }

    public CWTPSocket(InetAddress toAddress, int toPort, InetAddress localAddress,
        int localPort, IWTPUpperLayer upperLayer) throws SocketException {

  if(TcpUdp==1)
  {
    try {
      String str=toAddress.getHostAddress();
      TcpSocket = new Socket(toAddress.getHostAddress(), toPort);
      Tcpoutput=new DataOutputStream(TcpSocket.getOutputStream());
      Tcpinput=new DataInputStream(TcpSocket.getInputStream());
    }
    catch (UnknownHostException ex) {
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
    TcpSocket.setSoTimeout(1000);
  }
  else
  {
    if (localAddress == null) {
      socket = new DatagramSocket(localPort);
    }
    else {
      socket = new DatagramSocket(localPort, localAddress);
    }

    socket.setSoTimeout(1000);
  }

        this.upperLayer = upperLayer;
        this.toAddress = toAddress;
        this.toPort = toPort;
        this.setName("CWTPSocket-"+toAddress.getHostAddress()+":"+toPort);
        if (logger.isDebugEnabled()) {
          logger.debug("開始與網關建立連接 CWTPSocket-"+toAddress.getHostAddress()+":"+toPort);
        }
        isRunning=true;
        this.start();
    }

    public CWTPInitiator tr_invoke(IWTPUpperLayer upper_Layer,
        CWTPEvent initPacket, boolean ackType, byte classType) {
        return new CWTPInitiator(this, upper_Layer, initPacket, ackType,
            classType);
    }

    public void send(CWTPPDU pdu) {
        byte[] sendBytes = pdu.toByteArray();

        try {
             if(markflg.sendreflg==1)
             {
               tid++;
               System.out.println(tid+" Send data:" + sendBytes.length + " bytes");
             }
            if (logger.isDebugEnabled())
            {
                logger.debug("sending " + CWTPPDU.types[pdu.getPDUType()] +
                    ", TID: " + pdu.getTID());
                //logger.debug("\n"+Utils.hexDump("data to send: ", sendBytes));
            }
            if(TcpUdp==1)
            {
              Tcpoutput.write(sendBytes);
            }
            else
            {
              socket.send(new DatagramPacket(sendBytes, sendBytes.length,
                                             toAddress, toPort));
            }
        } catch (IOException e) {
            logger.error("IOException while sending.", e);
        }
    }

    /**
     * This method in an (endless) loop receives DatagramPackets (UDP)
     * by the DatagramSocket layer below.
     * <br>
     * Stopping: The loop can be interrupted by calling interrupt().
     * If you would like to stop the whole socket you better
     * should call close(). It also closes the DatagramSocket below.
     */
    public void run() {
         int i=0;
        while (isRunning) {
            logger.debug("WTP-Layer listening...");

            /** @todo MRU capability negotiation
             * The folowing number (1400) should not be hard coded!
             * It is the MRU that is negotiated via WSP.
             * This is part of the WSP CAPABILITY NEGOTIATION Task!
             */
            DatagramPacket in = new DatagramPacket(new byte[1500], 1500);

            try {
                while (isRunning) {
                    try {
                         if(TcpUdp==1)
                         {
                           int flag=0;
                           byte[] ReceiveByte=new byte[2084];
                           while(true)
                           {
                             Tcpinput.read(ReceiveByte);
                             if(ReceiveByte.equals("")||ReceiveByte==null)
                             {
                               break;
                             }
                             else
                             {
                               logger.debug("\n"+Utils.hexDump("data received: ", ReceiveByte));
                             flag=1;
                             }
                           }
                           if(flag==1)
                           {
                             break;
                           }

                         }
                         else
                         {
                           socket.receive(in);
                           byte ReceiveByte[] = in.getData();
                           if(markflg.sendreflg==1)
                          {
                            i++;
                           System.out.println(i+ " receive data:" + ReceiveByte.length + " bytes");
                           markflg.ReceiveBag(1);
                          }

                           logger.debug("\n"+Utils.hexDump("data received: ", ReceiveByte));
                           break;
                         }


                    } catch (InterruptedIOException ie) {
                        // timeout from read...
                    }
                }
            } catch (IOException e) {
                if (isRunning) {
                    logger.error("IOException from socket.receive()", e);
                }
            }

            // Have we been stopped?
            if (!isRunning) {
                break;
            }

            // is the remote host allowed to communicate with this session?
            // if not, ignore it!
            //if (toAddress.equals(in.getAddress()) && toPort == in.getPort()){
            // decode the bytes
            CWTPPDU pdu = null;
            IWTPTransaction transact = null;

            try {
                // uses now the actual data length from the DatagramPacket
                // instead of the length of the  byte[] buffer

                pdu = CWTPPDU.decode(in.getData(), in.getLength());


                if (logger.isDebugEnabled()) {
                    logger.debug("received WTP PDU: " +
                        CWTPPDU.types[pdu.getPDUType()] + " TID: " +
                        pdu.getTID() + " | " + (pdu.getTID() + 32768));
                }
            } catch (EWTPCorruptPDUException e) {
                // if the TID is available process in state machine
                // else: ignore
                if (e.isTidAvailable()) {
                    transact = getTransaction(e.getTid() + 32768);

                    if (transact != null) {
                        // process in state machine
                        transact.process(e);
                    }
                }
            }

            // associate the PDU with the corresponding transaction
            transact = getTransaction(pdu.getTID() + 32768);

            if (transact == null) {
                // there is no transaction with this TID
                //logger.debug("new Transaction");
                // if rcvInvoke start new transaction:
                if (pdu.getPDUType() == CWTPPDU.PDU_TYPE_INVOKE) {
                    CWTPInvoke pdu2 = (CWTPInvoke) pdu;

                    if ((pdu2.getTCL() == CWTPInitiator.CLASS_TYPE_1) ||
                            (pdu2.getTCL() == CWTPInitiator.CLASS_TYPE_2)) {
                        CWTPResponder resp = new CWTPResponder(this,
                                upperLayer, pdu2, pdu2.getU_P(), pdu2.getTCL());
                    }
                }

                // if Ack PDU with TIDve flag set, send abort PDU
                if (pdu.getPDUType() == CWTPPDU.PDU_TYPE_ACK) {
                    if (((CWTPAck) pdu).getTve_tok()) {
                        send(new CWTPAbort(CWTPAbort.ABORT_REASON_INVALIDTID));
                    }
                }

                // else: ignore
            } else {
                // pdu is associated with transaction
                try {
                    //logger.debug("PDU associated");
                    // process in state machine of transaction
                    transact.process(pdu);
                } catch (EWTPAbortedException e3) {
                    logger.warn("Transaction aborted", e3);
                    transact = getTransaction(pdu.getTID());

                    if (transact != null) {
                        removeTransaction(transact);
                    }
                }
            }
        }
        // Notify close()...
        synchronized(lock) {
            lock.notifyAll();
        }
    }

    /**
     * Close the socket. Closes the underliing DatagramSocket (UDP)
     */
    public void close() {
        logger.debug("close(): Closing socket");
        isRunning=false;
        socket.close();
        if( Thread.currentThread() != this ) {
            synchronized(lock) {
                try {
                    logger.debug("close(): waiting for thread to finish");
                    lock.wait(5000); // Wait max 5 secs for reader thread to terminate...
                    logger.debug("close(): done");
                } catch (InterruptedException e) {}
            }
        }
    }

    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //XXXXXXXXXXXXXXX get/add/remove transactions XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    public boolean addTransaction(IWTPTransaction t) {
        Integer tid = new Integer(t.getTID());

        synchronized (transactions) {
            if (transactions.containsKey(tid)) {
                return false;
            }

            transactions.put(tid, t);
        }

        return true;
    }

    public IWTPTransaction getTransaction(int TID) {
        Integer tid = new Integer(TID);

        return (IWTPTransaction) transactions.get(tid);
    }

    public boolean removeTransaction(IWTPTransaction t) {
        Integer tid = new Integer(t.getTID());

        return transactions.remove(tid) != null;
    }

    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //XXXXXXXXXXXXXXX getter/setter XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    public InetAddress getLocalAddress() {
        return socket.getLocalAddress();
    }

    public int getLocalPort() {
        return socket.getLocalPort();
    }

    public InetAddress getRemoteAddress() {
        return toAddress;
    }

    public int getRemotePort() {
        return toPort;
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人av在线一区二区| 一本一本久久a久久精品综合麻豆| 亚洲成人手机在线| 一区二区三区日韩精品视频| 最新不卡av在线| 亚洲视频图片小说| 亚洲免费观看视频| 亚洲一区在线电影| 亚洲成在人线免费| 亚洲国产精品影院| 亚洲午夜精品17c| 亚洲一区二区三区四区在线| 一区二区在线观看免费| 1区2区3区精品视频| 亚洲视频狠狠干| 亚洲欧美偷拍三级| 亚洲综合在线电影| 一区二区三区 在线观看视频| 一个色综合av| 亚洲黄色录像片| 日韩在线一区二区| 国产精品资源在线观看| 一区二区三区不卡在线观看| 亚洲综合999| 亚洲一区欧美一区| 日本亚洲欧美天堂免费| 麻豆91在线看| 成人黄色777网| 99re这里只有精品6| 欧美午夜精品免费| 欧美日韩一区二区欧美激情| 日本高清视频一区二区| 欧美精品少妇一区二区三区| 91精品国产综合久久久久久漫画| 欧美电影免费提供在线观看| 精品福利视频一区二区三区| 综合av第一页| 亚洲成人免费影院| 亚洲成人精品在线观看| 极品美女销魂一区二区三区| 国产美女在线观看一区| 色综合久久88色综合天天6| 一本大道av伊人久久综合| 日韩欧美一区二区三区在线| 欧美精品一区二区三区高清aⅴ| 亚洲欧洲性图库| 亚洲夂夂婷婷色拍ww47| 亚洲成人免费在线观看| 国产成人精品亚洲午夜麻豆| 91极品视觉盛宴| 欧美成人精品高清在线播放| 国产精品乱码一区二区三区软件| 亚洲成av人综合在线观看| 蜜桃视频在线观看一区二区| 99久久伊人网影院| 欧美三级乱人伦电影| 日韩视频免费观看高清完整版在线观看 | 日本不卡不码高清免费观看| 蜜臀99久久精品久久久久久软件| 97aⅴ精品视频一二三区| 欧美精品一卡两卡| 中文字幕亚洲不卡| 日韩av一级片| 91黄视频在线观看| 日韩欧美一卡二卡| 亚洲激情综合网| 国产在线不卡一区| 午夜视黄欧洲亚洲| av在线不卡观看免费观看| 欧美人狂配大交3d怪物一区| 国产色综合一区| 亚洲成人资源网| 91麻豆精品国产自产在线观看一区| 国产精品丝袜久久久久久app| 亚洲香蕉伊在人在线观| 国产成人午夜精品5599| 欧美日韩国产综合视频在线观看| 久久久欧美精品sm网站| 亚洲自拍另类综合| 奇米精品一区二区三区在线观看一 | 欧美激情一区在线观看| 三级成人在线视频| 在线亚洲高清视频| 中文字幕精品一区二区三区精品| 免费观看在线色综合| 91天堂素人约啪| 国产三级欧美三级日产三级99| 蜜臀av在线播放一区二区三区| 91在线一区二区| 久久久久久久久久久电影| 一区二区三区免费| 成人美女视频在线观看| 日韩亚洲欧美综合| 蜜桃视频在线观看一区二区| 欧美中文字幕一区| 一区二区三国产精华液| 国产69精品久久777的优势| 久久综合色之久久综合| 石原莉奈一区二区三区在线观看| 精品视频一区二区三区免费| 中文字幕综合网| 91啪亚洲精品| 国产精品久久久久久一区二区三区| 蜜臀99久久精品久久久久久软件| 欧美日韩在线一区二区| 中文字幕乱码一区二区免费| 丁香激情综合国产| 2022国产精品视频| 国产99久久久国产精品潘金| 精品国产第一区二区三区观看体验| 韩国精品一区二区| 日韩欧美一级精品久久| 久久不见久久见免费视频1| 欧美浪妇xxxx高跟鞋交| 日本视频一区二区三区| 欧美一区永久视频免费观看| 久久爱另类一区二区小说| 日韩天堂在线观看| 韩国毛片一区二区三区| 26uuu久久天堂性欧美| 国产不卡高清在线观看视频| 久久久久88色偷偷免费| 麻豆国产精品官网| 国产亚洲欧美一级| 精品一区二区在线视频| 久久久99精品久久| 成人做爰69片免费看网站| 久久av老司机精品网站导航| 久久综合色婷婷| 91在线观看一区二区| 日韩一区在线看| 欧美狂野另类xxxxoooo| 秋霞成人午夜伦在线观看| 国产色产综合产在线视频| 国产馆精品极品| 亚洲男女毛片无遮挡| 欧美色精品天天在线观看视频| 美女一区二区三区| 久久综合久久鬼色中文字| av男人天堂一区| 亚洲激情欧美激情| 精品久久久久久最新网址| 国产伦理精品不卡| 亚洲精品免费一二三区| 欧美午夜精品一区二区三区| 国精品**一区二区三区在线蜜桃| 久久久电影一区二区三区| 色94色欧美sute亚洲线路二 | 成人免费视频app| 亚洲伦理在线精品| 精品人在线二区三区| 国产成人免费在线视频| 亚洲一区二区在线观看视频| 日韩一本二本av| 91免费版pro下载短视频| 亚洲bt欧美bt精品| 国产喷白浆一区二区三区| 一本色道亚洲精品aⅴ| 久久成人精品无人区| 国产精品美女一区二区| 日韩午夜在线播放| 粉嫩久久99精品久久久久久夜| 日韩二区在线观看| 国产精品乱人伦| 日韩欧美不卡在线观看视频| av在线不卡观看免费观看| 日本不卡一二三| 国产精品污网站| 精品久久久久久久久久久院品网| 97久久精品人人做人人爽50路| 精品在线一区二区| 亚洲精品午夜久久久| 久久久国产精品午夜一区ai换脸| 欧美在线综合视频| 波多野结衣中文字幕一区二区三区| 五月综合激情日本mⅴ| 国产精品国产三级国产aⅴ无密码| 这里只有精品免费| 91丨porny丨户外露出| 久久99久久精品欧美| 成人免费在线视频观看| 日韩午夜在线影院| 色网站国产精品| 国产精品一区二区在线看| 日本aⅴ亚洲精品中文乱码| 国产精品国产自产拍在线| 久久精品一二三| 欧美一级片在线观看| 欧美午夜寂寞影院| 波多野结衣欧美| 成人免费三级在线| 日韩精品一二区| 无码av中文一区二区三区桃花岛| 亚洲精品五月天| 中文字幕欧美激情一区| 久久婷婷综合激情| 日韩一区二区三区三四区视频在线观看| 欧美日韩精品电影| 91污在线观看| 色哟哟国产精品免费观看|