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

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

?? serverconnectionhandler.java

?? J2ME MIDP_Example_Applications
?? JAVA
字號(hào):
// Copyright 2004 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation.
// Java and all Java-based marks are trademarks or registered trademarks of
// Sun Microsystems, Inc.
// Other product and company names mentioned herein may be trademarks or
// trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.


package example.btsppecho.server;


import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.bluetooth.ServiceRecord;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

import example.btsppecho.MIDletApplication;
import example.btsppecho.LogScreen;


public class ServerConnectionHandler
    implements Runnable
{
    private final static byte ZERO = (byte) '0';
    private final static int LENGTH_MAX_DIGITS = 5;

    // this is an arbitrarily chosen value:
    private final static int MAX_MESSAGE_LENGTH =
                             65536 - LENGTH_MAX_DIGITS;

    private final ServiceRecord serviceRecord;
    private final int requiredSecurity;
    private final ServerConnectionHandlerListener listener;
    private final Hashtable sendMessages = new Hashtable();

    private StreamConnection connection;
    private OutputStream out;
    private InputStream in;
    private volatile boolean aborting;
    private Writer writer;


    public ServerConnectionHandler(
               ServerConnectionHandlerListener listener,
               ServiceRecord serviceRecord,
               int requiredSecurity)
    {
        this.listener = listener;
        this.serviceRecord = serviceRecord;
        this.requiredSecurity = requiredSecurity;
        aborting = false;

        connection = null;
        out = null;
        in = null;
        listener = null;

        // the caller must call method 'start'
        // to start the reader and writer
    }


    public ServiceRecord getServiceRecord()
    {
        return serviceRecord;
    }


    public synchronized void start()
    {
        Thread thread = new Thread(this);
        thread.start();
    }


    public void close()
    {
        if (!aborting)
        {
            synchronized(this)
            {
                aborting = true;
            }

            synchronized(sendMessages)
            {
                sendMessages.notify();
            }

            if (out != null)
            {
                try
                {
                    out.close();
                    synchronized (this)
                    {
                        out = null;
                    }
                }
                catch(IOException e)
                {
                    // there is nothing we can do: ignore it
                }
            }

            if (in != null)
            {
                try
                {
                    in.close();
                    synchronized (this)
                    {
                        in = null;
                    }
                }
                catch(IOException e)
                {
                    // there is nothing we can do: ignore it
                }
            }

            if (connection != null)
            {
                try
                {
                    connection.close();
                    synchronized (this)
                    {
                        connection = null;
                    }
                }
                catch (IOException e)
                {
                    // there is nothing we can do: ignore it
                }
            }
        }
    }



    public void queueMessageForSending(Integer id, byte[] data)
    {
        if (data.length > MAX_MESSAGE_LENGTH)
        {
            throw new IllegalArgumentException(
                          "Message too long: limit is " +
                          MAX_MESSAGE_LENGTH + " bytes");
        }

        synchronized(sendMessages)
        {
            sendMessages.put(id, data);
            sendMessages.notify();
        }
    }


    private void sendMessage(byte[] data)
        throws IOException
    {
        byte[] buf = new byte[LENGTH_MAX_DIGITS + data.length];
        writeLength(data.length, buf);
        System.arraycopy(data,
                         0,
                         buf,
                         LENGTH_MAX_DIGITS,
                         data.length);
        out.write(buf);
        out.flush();
    }


    public void run()
    {
        // the reader

        // 1. open the connection and streams, start the writer
        String url = null;
        try
        {
            // 'must be master': false
            url = serviceRecord.getConnectionURL(
                                  requiredSecurity,
                                  false);

            connection = (StreamConnection) Connector.open(url);
            in = connection.openInputStream();
            out = connection.openOutputStream();

            LogScreen.log("Opened connection & streams to: '" +
                      url + "'\n");

            // start the writer
            Writer writer = new Writer(this);
            Thread writeThread = new Thread(writer);
            writeThread.start();

            LogScreen.log("Started a reader & writer for: '" +
                      url + "'\n");

            // open succeeded, inform listener
            listener.handleOpen(this);
        }
        catch(IOException e)
        {
            // open failed, close any connections/streams, and
            // inform listener that the open failed

            LogScreen.log("Failed to open " +
                          "connection or streams for '" +
                           url + "' , Error: " +
                           e.getMessage());

            close();

            listener.handleOpenError(
                         this,
                         "IOException: '" + e.getMessage() + "'");

            return;
        }
        catch (SecurityException e)
        {
            // open failed, close any connections/streams, and
            // inform listener that the open failed

            LogScreen.log("Failed to open " +
                          "connection or streams for '" +
                           url + "' , Error: " +
                           e.getMessage());

            close();

            listener.handleOpenError(
                         this,
                         "SecurityException: '" + e.getMessage() + "'");

            return;
        }

        // 2. wait to receive and read messages
        while (!aborting)
        {
            int length = 0;
            try
            {
                byte[] lengthBuf = new byte[LENGTH_MAX_DIGITS];
                readFully(in, lengthBuf);
                length = readLength(lengthBuf);
                byte[] temp = new byte[length];
                readFully(in, temp);

                listener.handleReceivedMessage(this, temp);
            }
            catch (IOException e)
            {
                close();
                if (length == 0)
                {
                   listener.handleClose(this);
                }
                else
                {
                   // we were in the middle of reading...
                   listener.handleErrorClose(this, e.getMessage());
                }
            }
        }
    }


    private static void readFully(InputStream in, byte[] buffer)
        throws IOException
    {
        int bytesRead = 0;

        while (bytesRead < buffer.length)
        {
            int count = in.read(buffer,
                                bytesRead,
                                buffer.length - bytesRead);

            if (count == -1)
            {
                throw new IOException("Input stream closed");
            }
            bytesRead += count;
        }
    }


    private static int readLength(byte[] buffer)
    {
        int value = 0;

        for (int i = 0; i < LENGTH_MAX_DIGITS; ++i)
        {
            value *= 10;
            value += buffer[i] - ZERO;
        }
        return value;
    }


    private void sendMessage(OutputStream out, byte[] data)
        throws IOException
    {
        if (data.length > MAX_MESSAGE_LENGTH)
        {
            throw new IllegalArgumentException(
                          "Message too long: limit is: " +
                          MAX_MESSAGE_LENGTH + " bytes");
        }
        byte[] buf = new byte[LENGTH_MAX_DIGITS + data.length];
        writeLength(data.length, buf);
        System.arraycopy(data,
                         0,
                         buf,
                         LENGTH_MAX_DIGITS,
                         data.length);
        out.write(buf);
        out.flush();
    }


    private static void writeLength(int value, byte[] buffer)
    {
        for (int i = LENGTH_MAX_DIGITS -1; i >= 0; --i)
        {
            buffer[i] = (byte) (ZERO + value % 10);
            value = value / 10;
        }
    }


    private class Writer
        implements Runnable
    {
        private final ServerConnectionHandler handler;


        Writer(ServerConnectionHandler handler)
        {
            this.handler = handler;
        }


        public void run()
        {
            while (!aborting)
            {
                synchronized(sendMessages)
                {
                    Enumeration e = sendMessages.keys();
                    if (e.hasMoreElements())
                    {
                        // send any pending messages
                        Integer id = (Integer) e.nextElement();
                        byte[] sendData =
                               (byte[]) sendMessages.get(id);
                        try
                        {
                            sendMessage(out, sendData);

                            // remove sent message from queue
                            sendMessages.remove(id);

                            // inform listener that it was sent
                            listener.handleQueuedMessageWasSent(
                                         handler,
                                         id);
                        }
                        catch (IOException ex)
                        {
                            close(); // stop the networking thread

                            // inform that we got an error close
                            listener.handleErrorClose(handler,
                                                      ex.getMessage());
                        }
                    }

                    if (sendMessages.isEmpty())
                    {
                        try
                        {
                            sendMessages.wait();
                        }
                        catch (InterruptedException ex)
                        {
                            // this can't happen in MIDP: ignore it
                        }
                    }
                }
            }
        }
    }
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品在线观看播放| 91一区在线观看| 日韩亚洲欧美一区二区三区| 一区二区三区 在线观看视频| 国产成人精品影视| 国产免费成人在线视频| 国产寡妇亲子伦一区二区| 久久精品欧美日韩| 国产成人免费av在线| 国产丝袜欧美中文另类| 国产美女在线观看一区| 国产情人综合久久777777| 国产成a人亚洲精| 欧美国产视频在线| 91蜜桃在线观看| 亚洲一区二区黄色| 日韩一区二区在线看片| 国产一本一道久久香蕉| 国产精品福利一区二区三区| 91免费视频观看| 日韩av成人高清| 久久女同性恋中文字幕| 久久精品水蜜桃av综合天堂| 91在线小视频| 日韩1区2区3区| 国产三级精品三级在线专区| 91免费观看视频在线| 日本 国产 欧美色综合| 欧美国产禁国产网站cc| 91丝袜美腿高跟国产极品老师 | 91久久国产最好的精华液| 爽爽淫人综合网网站| 国产亚洲精久久久久久| 在线观看亚洲精品视频| 男女视频一区二区| 亚洲视频你懂的| 精品少妇一区二区三区在线播放| 成人动漫精品一区二区| 奇米影视一区二区三区| 国产精品一二三四五| 一区二区三区高清| 国产欧美日韩另类一区| 欧美裸体一区二区三区| 9i看片成人免费高清| 麻豆国产欧美一区二区三区| 亚洲欧美日韩在线| 337p粉嫩大胆噜噜噜噜噜91av| 日本韩国一区二区| 成人理论电影网| 国产一区二区三区观看| 性做久久久久久| 亚洲精品一二三| 国产精品免费视频一区| 天堂一区二区在线免费观看| 最好看的中文字幕久久| 中文av字幕一区| 久久久久久一级片| 久久一区二区视频| 日韩欧美中文字幕精品| 在线播放亚洲一区| 欧美日韩另类一区| 欧美日韩aaaaa| 欧美色图片你懂的| 69久久夜色精品国产69蝌蚪网| 欧美自拍偷拍午夜视频| 91麻豆免费看片| 91看片淫黄大片一级在线观看| 成人免费视频播放| av在线免费不卡| heyzo一本久久综合| av亚洲产国偷v产偷v自拍| 91视频观看视频| 欧美性感一类影片在线播放| 亚洲欧美另类久久久精品2019 | 91原创在线视频| 国产精品久久三| 亚洲欧美综合另类在线卡通| 中文字幕一区二| 一区二区在线免费| 99精品视频中文字幕| 欧美日韩国产首页| 久久综合九色综合欧美98 | 日韩免费福利电影在线观看| 高清国产午夜精品久久久久久| 久久久影视传媒| 国产女人18水真多18精品一级做| 亚洲欧美日韩精品久久久久| 国产福利一区二区三区| 精品污污网站免费看| 中文字幕在线观看一区二区| 久久国产福利国产秒拍| 97久久人人超碰| 欧美日韩成人一区二区| 久久久一区二区三区捆绑**| 亚洲免费视频中文字幕| 丝袜a∨在线一区二区三区不卡| 美女性感视频久久| 94色蜜桃网一区二区三区| 欧美午夜理伦三级在线观看| 欧美mv日韩mv国产网站| 国产精品久久久久久福利一牛影视 | 久久久九九九九| 午夜伦欧美伦电影理论片| 国产美女精品人人做人人爽 | 日av在线不卡| 色婷婷激情久久| 国产精品大尺度| 国产91丝袜在线播放| 精品国产制服丝袜高跟| 日韩高清一级片| 欧美无砖砖区免费| 亚洲在线视频免费观看| 在线视频欧美精品| 亚洲欧美日韩国产综合| 成人动漫一区二区| 综合久久国产九一剧情麻豆| 成人少妇影院yyyy| 亚洲国产成人私人影院tom| 国产成人综合视频| 欧美激情综合在线| 成人美女在线观看| 自拍偷拍欧美激情| 色嗨嗨av一区二区三区| 一二三区精品福利视频| 91国产免费看| 免费在线一区观看| 久久日一线二线三线suv| 国产福利一区二区| 国产精品卡一卡二| 在线免费观看成人短视频| 亚洲国产成人av好男人在线观看| 欧美日韩一区高清| 精品午夜一区二区三区在线观看| 久久综合久久综合亚洲| 成人激情免费网站| 亚洲欧美一区二区三区极速播放| 自拍偷拍亚洲欧美日韩| 日韩电影在线观看网站| 国产日本一区二区| 日韩一级大片在线| 精品视频在线看| 不卡欧美aaaaa| 国产99一区视频免费| 日韩不卡免费视频| 亚洲bt欧美bt精品| 1024成人网| 日韩视频一区二区| 99视频精品全部免费在线| 蜜臀av性久久久久蜜臀aⅴ| 亚洲免费观看视频| 国产午夜亚洲精品羞羞网站| 欧美伊人精品成人久久综合97| 国产成人亚洲综合a∨婷婷| 奇米影视7777精品一区二区| 亚洲精品日韩一| 亚洲欧美区自拍先锋| 精品国产乱码久久| 91精品国模一区二区三区| 色婷婷狠狠综合| 99久久久国产精品| 国产一区视频导航| 七七婷婷婷婷精品国产| 五月激情丁香一区二区三区| 一区二区在线观看av| 成人免费一区二区三区视频| 久久久www成人免费毛片麻豆 | 久久亚洲影视婷婷| 日韩欧美在线影院| 欧美伦理影视网| 日韩一区二区免费在线观看| 精品视频1区2区| 99精品一区二区| 91行情网站电视在线观看高清版| 91丨九色丨国产丨porny| 91丨九色porny丨蝌蚪| 91精品福利视频| 在线播放亚洲一区| 日韩女优视频免费观看| 日韩一区二区三区免费观看| 精品日韩在线一区| 久久一二三国产| 一色桃子久久精品亚洲| 亚洲欧美日韩在线播放| 亚洲成人精品一区| 狠狠色伊人亚洲综合成人| 国产成人精品午夜视频免费| 99精品黄色片免费大全| 欧美精品三级日韩久久| 久久久久久久综合色一本| 亚洲色图欧洲色图婷婷| 亚洲成年人网站在线观看| 美女免费视频一区| 99国内精品久久| 日韩三级视频中文字幕| 一区精品在线播放| 三级不卡在线观看| 不卡av免费在线观看| 在线成人午夜影院| 亚洲免费在线视频| 国产一区二区在线观看免费|