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

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

?? cwtpsocket.java~7~

?? jwap 協議 udp 可以用于手機通訊
?? JAVA~7~
字號:
/**
 * 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
                         {
                            markflg.ReceiveBag(0);
                           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一区二区三区免费野_久草精品视频
欧美一区二区三区啪啪| 国产精品77777竹菊影视小说| 在线观看一区二区精品视频| 一区二区三区日韩欧美精品 | 国产精品一区二区免费不卡 | 国产欧美精品一区aⅴ影院| 国产在线播放一区| 日日夜夜精品视频免费| 亚洲欧美电影一区二区| 欧美激情一区二区三区四区| 欧美www视频| 成人性生交大片| 一区2区3区在线看| 欧美一级日韩一级| 国模冰冰炮一区二区| 国产精品福利影院| 日韩免费看的电影| 99在线精品观看| 美女脱光内衣内裤视频久久影院| 久久久91精品国产一区二区三区| 色国产精品一区在线观看| 日韩高清国产一区在线| 国产精品久久久久久久蜜臀| 欧美色区777第一页| 成人综合在线视频| 久久国产精品72免费观看| 亚洲人成人一区二区在线观看 | 成人污视频在线观看| 99精品国产一区二区三区不卡| 亚洲夂夂婷婷色拍ww47| 久久婷婷成人综合色| 欧美中文字幕亚洲一区二区va在线 | 亚洲国产精品欧美一二99| 久久―日本道色综合久久| 欧美丰满一区二区免费视频 | 丁香啪啪综合成人亚洲小说 | 五月婷婷综合激情| 中文字幕日韩一区| 欧美精品一区二区三区在线 | 国产又粗又猛又爽又黄91精品| 亚洲综合丁香婷婷六月香| 国产精品久久久久久亚洲毛片| 精品乱人伦小说| 日韩一区二区精品在线观看| 91理论电影在线观看| 成人av电影在线网| 成人理论电影网| 99久久精品国产一区二区三区 | 成人av资源下载| 色哟哟亚洲精品| 91麻豆精品国产91久久久久久久久| 欧美亚洲自拍偷拍| 精品国产一区久久| 自拍偷在线精品自拍偷无码专区| 综合婷婷亚洲小说| 久久91精品国产91久久小草| 国产盗摄一区二区| 欧美精品乱码久久久久久| 欧美精品久久天天躁| 久久久久久久久99精品| 国产精品久久久久久久久晋中| 成人免费在线视频观看| 午夜精品aaa| 岛国精品一区二区| 欧美老肥妇做.爰bbww| 久久综合国产精品| 亚洲一区二区三区三| 蓝色福利精品导航| av影院午夜一区| 欧美成人高清电影在线| 亚洲另类春色国产| 国产福利一区二区| 91精品国产综合久久精品麻豆| 久久蜜臀中文字幕| 日韩精品久久久久久| 99视频超级精品| 久久综合色鬼综合色| 手机精品视频在线观看| 色香蕉成人二区免费| 久久久国产精华| 黄色小说综合网站| 日韩亚洲欧美在线观看| 一区二区三区不卡在线观看| 成人黄色国产精品网站大全在线免费观看| 欧美日韩国产精品自在自线| 亚洲人一二三区| 成人短视频下载| 国产精品传媒入口麻豆| 成人性视频免费网站| 国产色婷婷亚洲99精品小说| 精品亚洲免费视频| 精品处破学生在线二十三| 久久国产视频网| 欧美sm极限捆绑bd| 韩国成人精品a∨在线观看| 日韩精品一区二区三区视频在线观看| 亚洲国产另类av| 日韩欧美一区二区免费| 精品一区二区三区的国产在线播放| 91精品国产欧美一区二区| 欧美aaaaaa午夜精品| 久久久三级国产网站| 高清av一区二区| 一区二区三区在线免费播放| 欧美日韩国产影片| 精品制服美女久久| 亚洲国产精品成人综合 | 国产suv一区二区三区88区| 国产亚洲欧美在线| 色婷婷一区二区| 亚洲伊人色欲综合网| 欧美大片一区二区| 丁香婷婷深情五月亚洲| 亚洲成av人片在线观看无码| 91精品国产福利| bt欧美亚洲午夜电影天堂| 亚洲综合网站在线观看| 欧美刺激脚交jootjob| eeuss鲁一区二区三区| 免费在线一区观看| 国产精品每日更新| 日韩免费福利电影在线观看| 99久久99久久综合| 国产九色sp调教91| 日本免费新一区视频| 亚洲男同性视频| 中文字幕欧美三区| 日韩美一区二区三区| 色国产精品一区在线观看| 久草热8精品视频在线观看| 一区二区三区免费看视频| 欧美二区乱c少妇| 色视频一区二区| 国产在线看一区| 麻豆成人免费电影| 性久久久久久久久久久久| 中文字幕在线一区| 欧美国产日韩在线观看| 久久精品欧美一区二区三区不卡 | 91麻豆高清视频| 99精品国产视频| hitomi一区二区三区精品| 成a人片亚洲日本久久| 成人av资源站| 在线免费亚洲电影| 精品成人a区在线观看| 久久美女高清视频| 中文字幕av不卡| 亚洲婷婷综合久久一本伊一区| 亚洲欧美一区二区在线观看| 中文字幕中文字幕在线一区 | 一区二区高清在线| 视频一区视频二区在线观看| 丝袜美腿亚洲综合| 国产成人亚洲综合a∨猫咪| 懂色av一区二区三区免费观看| 色综合天天在线| 欧美日韩视频不卡| 久久蜜臀中文字幕| 一区二区久久久| 精品亚洲成a人在线观看 | 久久99国产精品尤物| 99在线热播精品免费| 777xxx欧美| 国产精品视频线看| 日韩精品福利网| a美女胸又www黄视频久久| 欧美精选一区二区| 亚洲国产精品ⅴa在线观看| 亚洲成av人片在线观看| 成人一道本在线| 欧美哺乳videos| 亚洲国产毛片aaaaa无费看| 成人av资源网站| 精品福利一二区| 日韩精品1区2区3区| 在线观看一区二区精品视频| 国产精品欧美一区二区三区| 日韩制服丝袜先锋影音| 91成人免费在线视频| 国产精品视频你懂的| 国产毛片精品国产一区二区三区| 91精品福利视频| 国产精品欧美久久久久无广告| 美女视频第一区二区三区免费观看网站 | 久久毛片高清国产| 国产综合色视频| 日韩一区二区在线观看视频| 亚洲第一福利一区| 欧美写真视频网站| 亚洲成人动漫在线免费观看| 在线视频一区二区三| 加勒比av一区二区| 欧美电影免费观看高清完整版在线观看| 亚洲一二三四在线观看| 91福利在线看| 日本特黄久久久高潮| 欧美一区二区啪啪| 精品一区二区三区免费| 久久免费精品国产久精品久久久久 |