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 6158971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:03:04+00:00 2026-05-23T21:03:04+00:00

It seems that when I use the accept method from the Socket class the

  • 0

It seems that when I use the accept method from the Socket class the whole program freezes up until data comes through. I’ve passed the socket to a thread and it doesn’t freeze but I need the thread to return data back which I don’t think it can do.

Code For getting useername

public boolean checkUsername() {
    NetworkIO n = new NetworkIO();
    // Grabs username from edittext field
    username = usernameEditText.getText().toString();
    System.out.println(usernameEditText.getText().toString());
    // queries databse for username
    try {
        resultFromServer = n.query("username",
                "select username FROM user_info  WHERE MATCH (username)  AGAINST ('"
                        + username + "' IN NATURAL LANGUAGE MODE);");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Code for NetworkIO class

public class NetworkIO extends Activity {
    Socket networkSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;


public String query(String request, String fieldRequested)
        throws IOException {

    // Tries to get connection
    try {

        networkSocket = new Socket("192.168.1.8", 9009);

        out = new PrintWriter(networkSocket.getOutputStream(), true);

        in = new BufferedReader(new InputStreamReader(
                networkSocket.getInputStream()));
        System.out.println("Hi from in made");
    } catch (UnknownHostException e) {
        System.err.println("Unknown host");
        System.exit(-1);

    } catch (IOException e) {
        System.err.println("IOException");
        System.exit(-1);
    }


    //Sends Request
    out.println(request);
    out.println(fieldRequested);
    String resultFromServer = "";

    //Waits for response and if its null exit
    while ((in.readLine()) != null) {
        resultFromServer += in.readLine();

    }
    System.out.println(resultFromServer);

    //Close the connections
    out.close();
    in.close();
    networkSocket.close();


    return resultFromServer;
}
}

Any criticism of my code will be much appreciated 🙂

  • 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-23T21:03:05+00:00Added an answer on May 23, 2026 at 9:03 pm

    The usual pattern is to run the accept loop inside a thread, and have a separate thread pool of handlers that you dispatch requests to.

    When you get a new socket from accept, hand the socket over to a worker thread to process. That way you don’t ever need to pass anything back to your main thread.

    Example is straight out of the ExecutorService javadocs: http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html

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

Sidebar

Related Questions

It seems that the choice to use string parsing vs. regular expressions comes up
Seems that requirements on safety do not seem to like systems that use AI
It seems that when I use a tool (such as winmerge) to update my
It seems that when we use form_for @story do |f| then Story has to
I have been reading up on this, and it seems that if you use
It seems that MSMQ doesn't use any Database management system to manage messages. How
it seems that I just solved my problem why I couldn't use the ASP.NET
It seems that in the future, we can just use the non-beta iPhone SDK
I want to use deep zoom in Silverlight, but it seems that the images
In XHTML Strict, it seems that you're not allowed to use the <u> tag

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.