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

  • SEARCH
  • Home
  • 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 9226473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:50:21+00:00 2026-06-18T04:50:21+00:00

I am not sure if my question is right…@@ (complete source code: https://github.com/oNaiPs/droid-VNC-server )

  • 0

I am not sure if my question is right…@@

(complete source code: https://github.com/oNaiPs/droid-VNC-server)

I run the source code in the above link on Windows XP, Eclipse AVD(API level 14), and it failed at the step to start the sever.

While I am tracing the code in debug mode, I got an exception on this code

public static boolean isServerRunning() {
    try {
        byte[] receiveData = new byte[1024];
        DatagramSocket clientSocket = new DatagramSocket();
        InetAddress addr = InetAddress.getLocalHost();

        clientSocket.setSoTimeout(100);
        String toSend = "~PING|";
        byte[] buffer = toSend.getBytes();

        DatagramPacket question = new DatagramPacket(buffer, buffer.length,
                addr, 13132);
        clientSocket.send(question);

        DatagramPacket receivePacket = new DatagramPacket(receiveData,
                receiveData.length);
        clientSocket.receive(receivePacket);
        String receivedString = new String(receivePacket.getData());
        receivedString = receivedString.substring(0, receivePacket
                .getLength());

        return receivedString.equals("~PONG|");
    } catch (Exception e) {
        return false;
    }
}

when it run to this line “clientSocket.receive(receivePacket);”

it goes to “catch (Exception e)”

The content of variable e is

e:                       SocketTimeOutException (id=830027971416)
   bytes Transferred      0
  +cause                  ErrorException (id=830029535888)
   detailMessage          null
  +stackState             (id=830027970928)
   stackTrace             null
  +suppressedExceptions   ArrayList(id=830027971456)

Now I know its an exception cause by the sever didn’t answer on time.(Thanks for Class Stacker). So I comment this line “clientSocket.setSoTimeout(100);” to waited a long time and find out it still stuck.

I don’t know if there should be some device connected when running the AVD, or it can just run on the AVD only.

I look the variable “clientSocket”, it’s subcontent “address” got a null and the “port” got a -1 after this line “clientSocket.send(question);”. Is this a correct result? (I read the explanation of the class on the android package website, but remain not understand. http://developer.android.com/reference/java/net/DatagramSocket.html)

  • 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-06-18T04:50:22+00:00Added an answer on June 18, 2026 at 4:50 am

    As discussed, you’re not creating a separate Thread for this test. This “fake client” code runs in the server app, in the same Thread which should serve the PING request and provide the PONG response.

    One quick solution would be to wrap this code inside a Runnable and start a separate Thread for it. A quick start example would be (throwing away the result for now,

    # start your concurrent request on-the-fly
    Thread serverTest = new Thread(new Runnable() { public void run() { isServerRunning(); }});
    serverTest.start();
    

    But please study the details about concurrency, synchronized, volatile and using HandlerThread and AsyncTask rather than Thread on Android.

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

Sidebar

Related Questions

Not sure if I'm phrasing my question right, but I have the code below.
I'm not sure I'm asking the right question here, but I'm looking to provide
Not sure if this is the right forum for me to ask this question.
I'm not sure StackOverflow is the right place to ask this question, because this
im not sure if i say it right. my question is how can i
I'm not sure if this is the right place to post this question but
I'm not sure if this is the right place for this question, but here
I am not sure if this will be right place to ask the question,
I've googled around but i'm not sure i am asking the right question or
I must admit, I am not even sure if I put the question right...

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.