Code example for DatagramChannel

Methods: send

0
            mPacketBuffer.putFloat(x);
            mPacketBuffer.putFloat(y);
            mPacketBuffer.flip();
 
            try { 
                mChannel.send(mPacketBuffer, mServerAddr);
            } catch (IOException e) {
                // TODO Auto-generated catch block 
                e.printStackTrace();
            } 
        } 
    } 
 
    private void onNewPosition(float x, float y) {
        // update the UI 
        mVwCoordinate.setPosition((float) x, (float) y);
        mTvAcceleration.setText(String.format("%.4f %.4f", x, y));
        mVwCoordinate.invalidate();
 
        sendMovePacket(x, y);
    }