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

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

?? cwtpsocket.java~6~

?? jwap 協(xié)議 udp 可以用于手機通訊
?? JAVA~6~
字號:
/**
 * 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("開始與網(wǎng)關建立連接 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一区二区三区免费野_久草精品视频
中文字幕日韩欧美一区二区三区| jlzzjlzz欧美大全| 日本午夜精品视频在线观看 | 日韩一区欧美一区| 国产欧美一区二区精品性| 久久久综合九色合综国产精品| 欧美大片顶级少妇| 久久人人爽人人爽| 久久精品人人做人人综合 | 日韩中文字幕1| 免费成人你懂的| 老鸭窝一区二区久久精品| 精品一区二区在线视频| 国产九色sp调教91| 大白屁股一区二区视频| 99久久精品久久久久久清纯| 色综合久久六月婷婷中文字幕| 色婷婷av一区二区三区之一色屋| 欧美日韩一区二区电影| 91精品国产黑色紧身裤美女| 日韩欧美国产不卡| 国产日韩在线不卡| 一级女性全黄久久生活片免费| 亚洲大片免费看| 久久99精品久久久| 国产成人啪免费观看软件| 9久草视频在线视频精品| 欧美探花视频资源| 日韩欧美亚洲一区二区| 中文av一区特黄| 亚洲一二三级电影| 美女性感视频久久| 成人av网址在线观看| 欧美性做爰猛烈叫床潮| 日韩久久久久久| 国产精品美女久久久久高潮| 亚洲视频免费观看| 肉色丝袜一区二区| 国产精品一区二区免费不卡 | aaa亚洲精品一二三区| 欧美久久久久久久久| 久久青草欧美一区二区三区| 亚洲色图一区二区| 免费高清视频精品| eeuss影院一区二区三区| 欧美日韩综合不卡| 日本一区二区综合亚洲| 亚洲妇女屁股眼交7| 国产精品亚洲综合一区在线观看| 在线观看三级视频欧美| wwwwxxxxx欧美| 玉足女爽爽91| 国产一区二区三区四区五区入口 | 高清成人在线观看| 欧美日韩二区三区| 欧美国产精品久久| 日本不卡免费在线视频| 97久久久精品综合88久久| 日韩一区二区中文字幕| 一区二区中文字幕在线| 看电视剧不卡顿的网站| 在线观看免费一区| 国产精品国产馆在线真实露脸| 蜜臀va亚洲va欧美va天堂| 色吧成人激情小说| 日本一区二区三级电影在线观看 | 久久精品国产澳门| 色综合天天综合网天天看片| 国产日产精品1区| 蜜臀久久99精品久久久画质超高清 | 精品午夜久久福利影院| 欧美午夜精品一区二区蜜桃| 欧美国产日韩一二三区| 加勒比av一区二区| 欧美丰满少妇xxxxx高潮对白 | 国产美女娇喘av呻吟久久| 欧美狂野另类xxxxoooo| 一区二区三区91| 不卡av在线免费观看| wwwwww.欧美系列| 久久不见久久见中文字幕免费| 欧美日韩亚洲综合在线| 国产精品不卡一区| 国产成人精品免费| 精品国产免费视频| 免费精品视频在线| 欧美一区二区视频在线观看| 亚洲一区二区黄色| 日本丰满少妇一区二区三区| 中文字幕在线不卡国产视频| 粉嫩av一区二区三区在线播放| 日韩一级二级三级| 日本va欧美va瓶| 8v天堂国产在线一区二区| 亚洲成人激情自拍| 欧美日韩精品欧美日韩精品 | 91网站最新地址| 国产精品久久久久久久久图文区 | 首页综合国产亚洲丝袜| 欧美视频第二页| 亚洲国产综合色| 欧美日韩国产精品成人| 亚洲成人你懂的| 3atv一区二区三区| 麻豆一区二区在线| 精品成人一区二区三区四区| 精品中文字幕一区二区| 久久综合给合久久狠狠狠97色69| 久久精品72免费观看| 久久在线观看免费| 国产91精品久久久久久久网曝门| 日本一区二区成人在线| 成+人+亚洲+综合天堂| 香蕉久久夜色精品国产使用方法| 欧美精品久久久久久久多人混战 | 国产午夜精品一区二区三区视频 | 国内精品伊人久久久久av影院 | 亚洲欧洲日韩综合一区二区| 99国产精品久久| 一区二区三区欧美日韩| 欧美日韩色综合| 美女视频一区二区| 久久精子c满五个校花| 99久久久久免费精品国产| 亚洲一区中文日韩| 欧美一二区视频| 国产激情视频一区二区在线观看 | 国产盗摄一区二区| 亚洲欧美电影一区二区| 欧美日韩中文字幕一区二区| 久久99久久99小草精品免视看| 久久欧美一区二区| 91玉足脚交白嫩脚丫在线播放| 亚洲小说欧美激情另类| 欧美成人性战久久| 99精品国产99久久久久久白柏| 香蕉成人啪国产精品视频综合网| 精品av久久707| 91论坛在线播放| 日精品一区二区| 国产精品蜜臀在线观看| 欧美日本国产视频| 国产精品996| 亚洲电影一级片| 国产午夜精品一区二区三区四区| 欧美在线不卡视频| 精品一区二区三区免费观看| 国产精品卡一卡二| 欧美精品久久99久久在免费线| 国产精品一区二区视频| 亚洲国产你懂的| 久久精品男人的天堂| 欧美在线观看视频在线| 国产在线播精品第三| 一区二区三区高清在线| 精品国产91乱码一区二区三区 | 日韩久久久久久| 日本久久一区二区三区| 精品无人码麻豆乱码1区2区| 一区二区三区在线观看网站| 久久先锋影音av鲁色资源网| 欧美三电影在线| www.亚洲色图.com| 久久国产欧美日韩精品| 亚洲一区二区在线免费观看视频| 国产欧美一区二区精品性色| 欧美一区二区三区人| 一本在线高清不卡dvd| 国产九色sp调教91| 日韩成人免费电影| 亚洲精品一二三| 午夜国产不卡在线观看视频| 久久久精品tv| 欧美一级高清大全免费观看| 日本精品一级二级| 粉嫩绯色av一区二区在线观看| 精品一区二区影视| 日本成人中文字幕| 亚洲一卡二卡三卡四卡五卡| 中文字幕第一区第二区| 欧美大胆人体bbbb| 欧美日韩国产高清一区| 91国偷自产一区二区三区观看| 高清不卡一区二区| 韩国精品一区二区| 热久久久久久久| 午夜精品福利在线| 亚洲综合无码一区二区| 中文字幕在线不卡| 欧美激情一二三区| 久久久久久免费毛片精品| 欧美一区二区三区在线看| 欧美色综合天天久久综合精品| 99在线精品观看| voyeur盗摄精品| 国产成人精品影院| 国产一区不卡在线| 精品一区二区精品| 久久99精品国产麻豆不卡| 久久99精品国产.久久久久久|