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

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

?? cwtpsocket.java

?? jwap 協議 udp 可以用于手機通訊
?? JAVA
字號:
/**
 * 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);
      //socket = new DatagramSocket();
    }
    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();
                           socket.receive(in);
                           byte ReceiveByte[] = in.getData();
                           if(markflg.sendreflg==1)
                          {
                            i++;
                           System.out.println(i+ " receive data:" + ReceiveByte.length + " bytes");
                           markflg.ReceiveBag();
                          }

                           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一区二区三区免费野_久草精品视频
国产精品免费免费| 亚洲成人自拍偷拍| 丁香另类激情小说| 国产精品三级久久久久三级| 国产毛片精品视频| 精品美女在线播放| 国产成人亚洲综合a∨猫咪| 久久美女艺术照精彩视频福利播放 | 国产精品成人网| 91影视在线播放| 久久电影网电视剧免费观看| 亚洲精品一区二区三区99| 国产乱码精品一区二区三| 亚洲影院免费观看| 2024国产精品视频| 在线免费视频一区二区| 国产在线精品一区在线观看麻豆| 久久久久久久免费视频了| 99riav久久精品riav| 在线成人av影院| 高清成人免费视频| 欧美aaa在线| 日韩国产欧美三级| 亚洲欧洲日产国码二区| 精品成人佐山爱一区二区| 欧美视频一区二区三区在线观看 | 国产精品国产a| 国产午夜亚洲精品羞羞网站| 欧美日韩精品欧美日韩精品一 | 欧美视频一区二区三区在线观看| 久久精品国产成人一区二区三区| 一区二区高清在线| 亚洲精品日韩一| 国产精品不卡一区| 亚洲欧美在线视频| 国产精品五月天| 中文字幕视频一区| 综合欧美一区二区三区| 亚洲女同ⅹxx女同tv| 久久精品视频网| 日韩一区欧美小说| 亚洲激情在线播放| 日日摸夜夜添夜夜添亚洲女人| 亚洲高清免费一级二级三级| 丝袜美腿亚洲综合| 久久不见久久见免费视频7| 国产精品综合视频| av电影一区二区| 在线观看91精品国产入口| 高清成人在线观看| 蜜臀av一区二区| 国产精品18久久久久久久久 | 毛片不卡一区二区| 看片网站欧美日韩| 久久99热国产| 一本色道亚洲精品aⅴ| 欧美精品一卡二卡| 亚洲人成电影网站色mp4| 男女男精品视频网| 在线精品视频小说1| 日韩欧美一级二级| 亚洲影视在线播放| eeuss鲁片一区二区三区在线看| 欧美日韩不卡在线| 亚洲精品五月天| 成人免费毛片app| 亚洲黄色录像片| 国产精品1区2区| 欧美一级高清片在线观看| 亚洲三级理论片| 91丨九色porny丨蝌蚪| 久久精品人人做人人爽人人| 视频一区欧美精品| 欧美日韩黄色一区二区| 亚洲免费观看高清完整版在线观看| 久久99精品久久久| 日韩一区二区三区视频在线 | 午夜精品影院在线观看| 99这里都是精品| 亚洲乱码国产乱码精品精98午夜| 国产激情视频一区二区在线观看| 精品国产制服丝袜高跟| 国产一区二区三区观看| 亚洲精品一区二区三区精华液| 麻豆一区二区在线| 国产精品嫩草影院av蜜臀| 性久久久久久久久| 日本不卡的三区四区五区| 69堂成人精品免费视频| 日本亚洲欧美天堂免费| 欧美v亚洲v综合ⅴ国产v| 麻豆精品国产91久久久久久 | 欧美tickling挠脚心丨vk| 国产精品一卡二卡| 亚洲一区二区五区| 精品国产免费视频| 一本一道综合狠狠老| 免费一级片91| 一区av在线播放| 国产午夜精品一区二区三区嫩草 | 91精品国产黑色紧身裤美女| 黄色资源网久久资源365| 成人免费在线观看入口| 日韩美女天天操| 欧美顶级少妇做爰| 色呦呦日韩精品| 99久久免费视频.com| 狠狠色丁香久久婷婷综| 国产日韩亚洲欧美综合| 欧美一级国产精品| 在线播放欧美女士性生活| av中文字幕亚洲| 国产一区二区h| 亚洲高清免费一级二级三级| 中文一区二区完整视频在线观看| 欧美电影影音先锋| 在线精品视频小说1| 色婷婷av一区二区三区gif| 粉嫩aⅴ一区二区三区四区五区| 免费在线视频一区| 韩国女主播一区二区三区| 亚洲chinese男男1069| 亚洲成人综合视频| 中文字幕精品一区二区精品绿巨人 | 国产精品一区一区三区| 日本中文字幕一区| 免费观看一级特黄欧美大片| 美女在线视频一区| 国产成人av在线影院| 国产精品一二三在| 成人av小说网| 欧美手机在线视频| 日韩精品一区在线| 欧美国产97人人爽人人喊| 《视频一区视频二区| 男人的j进女人的j一区| 高清日韩电视剧大全免费| 色综合久久88色综合天天免费| 欧美日韩亚洲高清一区二区| 日韩欧美国产精品一区| 国产精品视频yy9299一区| 性久久久久久久久| 精品亚洲国内自在自线福利| 国产美女在线精品| 制服丝袜成人动漫| 国产精品成人午夜| 国产一区欧美日韩| 欧美精选在线播放| 亚洲综合久久久| 成人看片黄a免费看在线| 日韩一区二区三区精品视频| 亚洲你懂的在线视频| 国产不卡在线一区| 久久婷婷久久一区二区三区| 亚洲精品视频在线观看免费| 久久精品噜噜噜成人88aⅴ| 欧美日韩亚洲另类| 一区二区三区国产精华| av电影在线观看不卡| 亚洲欧洲日本在线| 色爱区综合激月婷婷| 国产精品久久久久久久久免费丝袜| 韩国女主播成人在线观看| 欧美日本一道本| 欧美激情一区二区三区不卡| 日韩中文字幕麻豆| 欧美mv和日韩mv的网站| 国产在线播放一区| 国产日产欧产精品推荐色| 成人的网站免费观看| 亚洲精品精品亚洲| 欧美精三区欧美精三区| 老司机一区二区| 国产日韩欧美不卡| 本田岬高潮一区二区三区| 亚洲视频狠狠干| 91精品国产综合久久久蜜臀粉嫩 | 中文字幕在线不卡一区二区三区| 成人中文字幕合集| 亚洲综合男人的天堂| 制服丝袜亚洲精品中文字幕| 精品一区二区三区影院在线午夜| 99精品一区二区| 丝袜亚洲另类丝袜在线| 精品免费99久久| 视频在线在亚洲| 在线不卡一区二区| 国产传媒久久文化传媒| 成人免费在线视频观看| 欧美日韩中字一区| 国产馆精品极品| 亚洲1区2区3区4区| 欧美韩日一区二区三区四区| www..com久久爱| 一级特黄大欧美久久久| 欧美zozozo| 欧美日韩国产一级二级| 国产一区二区0| 久久91精品久久久久久秒播| 亚洲黄色在线视频|