示例#1
0
        private void handleRead(SelectionKey key)
        {
//        Log.d("MIDIPort2","handleRead");
            DatagramChannel c = (DatagramChannel)key.channel();
            UDPBuffer       b = (UDPBuffer)key.attachment();

            try {
                b.buffer.clear();
                b.socketAddress = c.receive(b.buffer);
                EventBus.getDefault().post(new PacketEvent(new DatagramPacket(b.buffer.array(), b.buffer.capacity(), b.socketAddress)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
示例#2
0
        private void handleWrite(SelectionKey key)
        {
            if (!outboundQueue.isEmpty())
            {
//            Log.d("MIDIPort2","handleWrite "+ outboundQueue.size());
                try {
                    DatagramChannel c = (DatagramChannel)key.channel();
                    DatagramPacket  d = outboundQueue.poll();

                    c.send(ByteBuffer.wrap(d.getData()), d.getSocketAddress());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
示例#3
0
        /*
         * We have some activity on the "debug selected" port. Handle it.
         */
        private void processDebugSelectedActivity(SelectionKey key)
        {
            Debug.Assert(key.acceptable);

            ServerSocketChannel acceptChan = (ServerSocketChannel)key.channel();

            /*
             * Find the debugger associated with the currently-selected client.
             */
            if (mSelectedClient != null)
            {
                Debugger dbg = mSelectedClient.debugger;

                if (dbg != null)
                {
                    Log.d("ddms", "Accepting connection on 'debug selected' port");
                    try
                    {
                        acceptNewDebugger(dbg, acceptChan);
                    }
                    catch (IOException)
                    {
                        // client should be gone, keep going
                    }

                    return;
                }
            }

            Log.w("ddms", "Connection on 'debug selected' port, but none selected");
            try
            {
                SocketChannel chan = acceptChan.accept();
                chan.close();
            }
            catch (IOException)
            {
                // not expected; client should be gone, keep going
            }
            catch (NotYetBoundException)
            {
                displayDebugSelectedBindError(mDebugSelectedPort);
            }
        }