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

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

?? cwtpsocket.java~1~

?? jwap 協議 udp 可以用于手機通訊
?? JAVA~1~
字號:
/**
 * 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[1400], 1400);

            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");
                          }

                           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一区二区三区免费野_久草精品视频
久久精品99国产精品| 国产精品成人网| 五月婷婷另类国产| 欧美唯美清纯偷拍| 日韩制服丝袜先锋影音| 精品欧美乱码久久久久久| 国产在线不卡一区| 亚洲视频一区二区在线| 欧美午夜电影在线播放| 精品一区二区影视| 国产清纯在线一区二区www| 99久久综合狠狠综合久久| 亚洲同性gay激情无套| 欧美精品乱人伦久久久久久| 国产综合久久久久久鬼色| 国产精品久久久爽爽爽麻豆色哟哟| 色综合天天天天做夜夜夜夜做| 亚洲一区在线观看免费观看电影高清| 色婷婷久久久久swag精品| 亚洲最大色网站| 久久久久亚洲蜜桃| 在线视频国内一区二区| 久久99热国产| 亚洲精品一二三四区| 日韩午夜激情免费电影| 不卡电影一区二区三区| 日韩国产高清影视| 国产精品久久久久久久午夜片| 在线不卡a资源高清| 国产·精品毛片| 午夜欧美视频在线观看 | 亚洲风情在线资源站| 91精品国产麻豆| 国产白丝网站精品污在线入口| 亚洲国产日日夜夜| 国产欧美精品一区二区三区四区| 99久久精品久久久久久清纯| 日本强好片久久久久久aaa| 国产精品久久久久久久久久久免费看 | 日韩美女啊v在线免费观看| 555www色欧美视频| 成人午夜短视频| 免费成人美女在线观看.| 亚洲欧美日韩电影| 久久亚洲二区三区| 色猫猫国产区一区二在线视频| 蜜臀av性久久久久蜜臀aⅴ流畅| 亚洲人成影院在线观看| 久久午夜老司机| 欧美群妇大交群的观看方式| 91香蕉国产在线观看软件| 国产在线精品免费| 加勒比av一区二区| 奇米色一区二区三区四区| 1024精品合集| 国产精品久久久久久久第一福利| 欧美电影免费观看高清完整版在 | 日韩精品一区二区三区四区 | 一区二区三区av电影 | 中文字幕一区在线观看| 久久久美女艺术照精彩视频福利播放| 欧美一区二区三区啪啪| 欧美在线影院一区二区| 一本一本久久a久久精品综合麻豆| 国产一区二区毛片| 久国产精品韩国三级视频| 日韩激情在线观看| 亚洲va欧美va国产va天堂影院| 亚洲免费成人av| 中文字幕av免费专区久久| 久久精品人人爽人人爽| 2019国产精品| 国产欧美日韩麻豆91| 日本一区二区三区在线观看| 欧美国产激情二区三区| 国产精品久久久久久亚洲毛片| 国产精品国产三级国产有无不卡| 国产精品国产三级国产三级人妇 | 欧美精品乱码久久久久久| 欧美性猛交一区二区三区精品 | 欧美一区二区三级| 欧美一二三区精品| 日韩精品一区二区三区视频在线观看 | 日韩三级电影网址| 精品国精品国产尤物美女| 精品国产百合女同互慰| 精品久久久久香蕉网| 国产亚洲欧美色| 日本一区二区三区在线观看| 亚洲精品一区二区三区蜜桃下载| 久久综合视频网| 中文字幕免费不卡| 中文在线资源观看网站视频免费不卡| 日韩欧美在线网站| 久久久久国产精品免费免费搜索| 亚洲国产成人午夜在线一区| 国产精品美女www爽爽爽| 亚洲天堂精品在线观看| 偷偷要91色婷婷| 另类小说欧美激情| 高清成人在线观看| 99久久国产综合精品女不卡| 欧美亚洲一区三区| 精品福利在线导航| 国产精品青草综合久久久久99| 亚洲美女视频在线观看| 免费人成黄页网站在线一区二区 | 成人免费毛片app| 欧美色倩网站大全免费| 日韩精品一区二区三区中文不卡 | 国产成+人+日韩+欧美+亚洲| 97se亚洲国产综合在线| 欧美日韩一二三区| 久久久久国产免费免费| 成人免费在线视频观看| 免费国产亚洲视频| 成人免费看黄yyy456| 8x8x8国产精品| 国产精品剧情在线亚洲| 亚洲一区二区三区四区在线观看 | 成人激情av网| 日韩一区二区三区三四区视频在线观看| 国产欧美视频一区二区三区| 午夜天堂影视香蕉久久| 99久久精品99国产精品| 精品久久久久久无| 亚洲主播在线播放| 成人免费视频网站在线观看| 欧美一级搡bbbb搡bbbb| 亚洲视频一二区| 国产麻豆9l精品三级站| 欧美日韩国产大片| 最近日韩中文字幕| 国产自产视频一区二区三区| 欧美日韩精品欧美日韩精品一| 国产精品毛片久久久久久久| 国产在线一区二区| 69久久99精品久久久久婷婷| 亚洲欧美一区二区三区极速播放| 国产一区二区三区不卡在线观看| 欧美日韩成人在线| 亚洲精品va在线观看| a级精品国产片在线观看| 久久综合九色综合欧美98 | 一区二区视频在线| 成人手机电影网| 国产午夜精品福利| 捆绑调教一区二区三区| 欧美色图第一页| 亚洲国产日韩精品| 色噜噜偷拍精品综合在线| 久久影院视频免费| 日韩中文字幕不卡| 色综合久久综合| 亚洲欧美日韩中文字幕一区二区三区| 国产一区二区福利| 久久天堂av综合合色蜜桃网| 免费观看久久久4p| 欧美一区二区三区系列电影| 一区二区三区四区精品在线视频 | 中文字幕在线不卡视频| 丁香六月久久综合狠狠色| 国产女同性恋一区二区| 精东粉嫩av免费一区二区三区| 欧美大片国产精品| 精品一区二区三区免费| 精品电影一区二区| 日韩av中文字幕一区二区三区| 91色视频在线| 亚洲老司机在线| 在线观看亚洲成人| 亚洲成人动漫一区| 91精品国产乱码久久蜜臀| 舔着乳尖日韩一区| 欧美成人激情免费网| 国产一本一道久久香蕉| 国产精品福利一区二区三区| 一本大道综合伊人精品热热| 一区二区三区欧美日| 欧美精品三级日韩久久| 久久精品国产精品亚洲精品| 久久综合国产精品| av毛片久久久久**hd| 亚洲制服欧美中文字幕中文字幕| 欧美日韩在线综合| 久久综合综合久久综合| 久久精品男人的天堂| 99久久夜色精品国产网站| 亚洲在线中文字幕| 欧美一区二区三区四区久久| 国模无码大尺度一区二区三区| 国产精品理论片| 欧美日韩高清影院| 国产在线播放一区| 亚洲欧美日韩国产综合| 欧美一区二区福利视频| 国产高清视频一区| 亚洲国产精品自拍| 久久免费精品国产久精品久久久久| 91视频免费看|