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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? cwtpsocket.java~9~

?? jwap 協(xié)議 udp 可以用于手機(jī)通訊
?? JAVA~9~
字號(hào):
/**
 * 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("開(kāi)始與網(wǎng)關(guān)建立連接 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;
    }
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日本在线播放| 欧美成人一区二区三区片免费| 欧美日韩国产高清一区| 久久综合给合久久狠狠狠97色69| 亚洲欧美色综合| 蓝色福利精品导航| 91精品办公室少妇高潮对白| 欧美成人在线直播| 午夜久久久久久久久久一区二区| 国产suv精品一区二区6| 欧美电影精品一区二区 | 99精品视频一区| 欧美一区二区三区小说| 亚洲伦在线观看| 成人在线综合网站| 欧美成人一区二区| 麻豆视频一区二区| 欧美日韩国产高清一区二区 | 91免费在线视频观看| 欧美sm极限捆绑bd| 日韩综合一区二区| 欧美天堂一区二区三区| 亚洲欧美电影一区二区| 成人免费视频app| 日本一区二区三区电影| 亚洲电影一区二区三区| www.亚洲在线| 国产午夜亚洲精品午夜鲁丝片| 国内精品久久久久影院色| 欧美一二三区在线观看| 日韩二区三区在线观看| 69精品人人人人| 午夜电影久久久| 欧美久久久久免费| 日韩精品成人一区二区三区| 欧美日韩一区二区三区四区 | 欧美色视频一区| 亚洲伊人伊色伊影伊综合网| 欧美自拍丝袜亚洲| 亚洲国产精品久久一线不卡| 欧美午夜一区二区| 婷婷久久综合九色综合伊人色| 欧美日韩三级一区| 免费在线观看一区二区三区| 日韩一区二区在线观看| 久久精品72免费观看| 久久夜色精品一区| 国产91丝袜在线18| 性久久久久久久| 欧美日产国产精品| 国产麻豆欧美日韩一区| 国产精品三级电影| 日本久久一区二区| 日本中文字幕一区二区有限公司| 日韩欧美色电影| 国产麻豆精品久久一二三| 中文字幕精品一区二区三区精品| 99精品久久只有精品| 亚洲成人免费在线观看| 日韩视频一区二区三区| 成人中文字幕电影| 亚洲永久精品国产| 精品国产免费一区二区三区四区 | 亚洲国产一区视频| 精品99一区二区| eeuss鲁片一区二区三区在线观看| 一区二区成人在线观看| 欧美日本高清视频在线观看| 国产在线不卡一区| 一区二区三区不卡视频在线观看 | 国产乱子伦一区二区三区国色天香| 国产网站一区二区三区| 欧美这里有精品| 国产精品一区在线| 亚洲自拍偷拍欧美| 久久久噜噜噜久久人人看| 色欧美88888久久久久久影院| 毛片一区二区三区| 一区二区三区中文字幕电影 | 亚洲免费在线电影| 日韩免费福利电影在线观看| 99vv1com这只有精品| 免费在线观看一区二区三区| 亚洲美女偷拍久久| 国产欧美精品国产国产专区| 在线综合+亚洲+欧美中文字幕| 高清在线不卡av| 午夜激情一区二区三区| 亚洲精品乱码久久久久久| 久久久久国产免费免费| 欧美久久一二区| 色www精品视频在线观看| 国产福利91精品一区| 蜜臀久久久久久久| 一级特黄大欧美久久久| 亚洲欧洲国产日本综合| 国产色综合久久| 久久蜜桃av一区精品变态类天堂 | 欧美视频一区二区三区四区| 成人在线视频一区| 国产露脸91国语对白| 秋霞午夜av一区二区三区| 亚洲在线观看免费视频| 日韩一区欧美一区| 国产精品网曝门| 久久综合一区二区| 亚洲精品一区二区三区蜜桃下载| 8x福利精品第一导航| 欧美日韩aaa| 制服丝袜一区二区三区| 欧美日韩mp4| 88在线观看91蜜桃国自产| 欧美性极品少妇| 欧美日韩精品三区| 久久人人97超碰com| 欧美一区二区日韩| 欧美日韩成人在线一区| 欧美精品日韩一本| 欧美日韩国产免费| 555www色欧美视频| 欧美一卡在线观看| 日韩欧美黄色影院| 26uuu国产在线精品一区二区| xfplay精品久久| 久久精品人人做人人综合| 久久亚洲春色中文字幕久久久| 久久免费国产精品| 亚洲欧洲日韩综合一区二区| 亚洲久草在线视频| 香蕉加勒比综合久久| 日韩精品成人一区二区三区| 久久99精品久久久久久久久久久久| 麻豆成人在线观看| 国产麻豆精品一区二区| 91视视频在线观看入口直接观看www| 91一区在线观看| 欧美理论电影在线| 欧美精品一区二区精品网| 国产精品你懂的| 亚洲成av人影院在线观看网| 免费精品视频在线| 粉嫩绯色av一区二区在线观看 | 亚洲高清免费在线| 蜜臀91精品一区二区三区| 韩国三级中文字幕hd久久精品| 大桥未久av一区二区三区中文| 色8久久人人97超碰香蕉987| 欧美日本视频在线| 亚洲精品一区二区三区四区高清| 中文字幕中文字幕一区二区| 亚洲成av人片一区二区梦乃 | 91视频你懂的| 91精品国产综合久久国产大片| 国产亚洲欧美激情| 一区二区三区精品视频| 韩国三级中文字幕hd久久精品| 色婷婷综合久色| 国产亚洲污的网站| 亚洲一区二区三区视频在线| 国内一区二区视频| 欧美亚洲自拍偷拍| 欧美成人伊人久久综合网| 亚洲精品免费视频| 国产麻豆午夜三级精品| 欧美三级乱人伦电影| 日本一区二区成人| 日本视频一区二区三区| 99国产欧美久久久精品| 欧美成人video| 亚洲国产视频网站| 成人黄色免费短视频| 欧美一级午夜免费电影| 亚洲女爱视频在线| 91婷婷韩国欧美一区二区| 日韩美一区二区三区| 一区二区三区产品免费精品久久75| 国产美女在线观看一区| 日韩无一区二区| 亚洲午夜电影在线观看| www.亚洲激情.com| 久久这里只精品最新地址| 亚洲r级在线视频| 一本色道久久综合亚洲aⅴ蜜桃 | 亚洲欧美另类综合偷拍| 国产精品91一区二区| 91精品国产高清一区二区三区蜜臀 | 亚洲超碰97人人做人人爱| 成人av在线影院| 国产亚洲综合av| 久久精品国产秦先生| 欧美精品vⅰdeose4hd| 亚洲综合色噜噜狠狠| 99精品视频中文字幕| 国产精品美女久久久久久久网站| 黄色成人免费在线| 久久这里只有精品首页| 国内欧美视频一区二区| 精品久久国产字幕高潮| 国产专区欧美精品| 久久综合九色综合欧美就去吻|