Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6142901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:27:01+00:00 2026-05-23T18:27:01+00:00

Simply said, I’m able to receive data from the connected socket, until about 10

  • 0

Simply said, I’m able to receive data from the connected socket, until about 10 seconds after it starts. The solution to fix this is, to send data to the ‘client'(an ARDrone) to keep the data stream going, otherwise it will stop sending data to the phone. However, my current code for some reason only writes data to the client (the ARDrone) on first connect and never after. I need it to keep sending data to the ARDrone even after the socket is communicating.

I’ve tried moving around the channel.register() calls, but nothing I’ve done seems to send data to the ARDrone, as I need.

Creating the connection:

channel = DatagramChannel.open();
channel.configureBlocking(false);
channel.socket().bind(new InetSocketAddress(video_port));
channel.connect(new InetSocketAddress(drone_addr, video_port));

selector = Selector.open();
channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);

Here is the current send/receive data function.

public void run() {
    try {
        ByteBuffer inbuf = ByteBuffer.allocate(BUFSIZE);
        done = false;
        while (!done) {
            selector.select();
        if (done) {
            disconnect();
            break;
        }
        Set readyKeys = selector.selectedKeys();
        Iterator iterator = readyKeys.iterator();
        while (iterator.hasNext()) {
            SelectionKey key = (SelectionKey) iterator.next();
            iterator.remove();
            if (key.isWritable()) {
                byte[] trigger_bytes = { 0x01, 0x00, 0x00, 0x00 };
                ByteBuffer trigger_buf = ByteBuffer.allocate(trigger_bytes.length);
                trigger_buf.put(trigger_bytes);
                trigger_buf.flip();
                channel.write(trigger_buf);
                channel.register(selector, SelectionKey.OP_READ);
            } else if (key.isReadable()) {
                inbuf.clear();
                int len = channel.read(inbuf);

                if (len > 0) {
                    inbuf.flip();
                    final BufferedVideoImage vi = new BufferedVideoImage();;
                    vi.addImageStream(inbuf);
                    drone.videoFrameReceived(0, 0, vi.getWidth(), vi.getHeight(), vi.getJavaPixelData(), 0, vi.getWidth());
                }
            }
        }

    } catch (Exception e) {
        drone.changeToErrorState(e);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:27:01+00:00Added an answer on May 23, 2026 at 6:27 pm

    I believe you corrupt your event interest on the first write with this line:

    channel.register(selector, SelectionKey.OP_READ);
    

    Per documentation, this resets it to OP_READ only.

    Edit 0:

    Per your comment – yes, I think you should remove that line entirely, and do not treat read and write cases as alternatives. In general a socket could be readable and writable at the same time. So what’s happening now is that the write case prevents the read case since UDP socket is always writable (versus TCP that buffers outgoing data).

    So my suggestion is to not include OP_WRITE into that event set at all, but handle writing in some other fashion, say on a timer, or after each read, or whatever makes sense to your app.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simply said: How do I receive data from a PHP echo to display using
Simply put, MVC is the pattern for separating contents (model) from presentation (view), and
EDIT seems my original post below might have been a bit long. Simply said,
my question simply relates to the difference in performance between a socket in C
From numerous other questions on SO it is said that in order to reset
I just came from a presentation by the Manhattan Borough President who said that
I am trying to render some data from a large XML using XSLT. The
Simply said I have to write an application to synchronise several database tables. Because
Other posters have previously said in this forum that when your Django app starts
Simply, are there any Java Developer specific Linux distros?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.