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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:17:23+00:00 2026-06-13T21:17:23+00:00

now i’m making socket connection to connect multiple client to one server. everything fine,

  • 0

now i’m making socket connection to connect multiple client to one server. everything fine, i make thread in different class. But when i will fill textView with string from thread activity, i can’t. please help

this MainActivity:

public class MainActivity extends Activity {

private static int port = 6000;
TextView txt;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    txt = (TextView) findViewById(R.id.txtCommand);
    txt.setText("Server : ");
    ServerSocket server1 = null;
    Server gameServer = new Server();
    try {
        server1 = new ServerSocket(port);
        // .. server setting should be done here
    } catch (IOException e) {
        System.out.println("Could not start server!");
       // return ;
    }

    while (true) {
        Socket client = null;
        try {
            client = server1.accept();
            gameServer.handleConnection(client);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

public class Server  {
    private ExecutorService executor = Executors.newCachedThreadPool();

    public void handleConnection(Socket client) throws IOException {    
        PlayerConnection newPlayer = new PlayerConnection(this, client);
        txt.setText(newPlayer.getuname());
        this.executor.execute(newPlayer);
    }

    // add methods to handle requests from PlayerConnection
}

and this thread adctivity :

public class PlayerConnection implements Runnable {
private Server parent;

private Socket socket;
private PrintWriter out;
private BufferedReader in;
String line;

protected PlayerConnection(Server parent, Socket socket) throws IOException {
    this.parent = parent;
    this.socket = socket;

    this.in = new BufferedReader(new InputStreamReader(socket
            .getInputStream()));
    this.out = new PrintWriter(new OutputStreamWriter(
            socket.getOutputStream()));     
}

public void run() {
    while(!this.socket.isClosed()) {                        
        try {
            //int nextEvent = this.in.readInt();
            line = in.readLine();
            System.out.println("Server Receive : "
                    + line);
            out.println("Server Sent :" +line);
            System.out.println("SEND : "
                    + line);
            out.flush();
             if (line == null){
                 this.socket.isClosed();
                 break;
             }
        } catch (IOException 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-06-13T21:17:25+00:00Added an answer on June 13, 2026 at 9:17 pm

    I realized that you have a while loop that never ends in your onCreate method. try to move that loop in to your thread. this loop blocks inputs of your application.

    while (true) {
        Socket client = null;
        try {
            client = server1.accept();
            gameServer.handleConnection(client);
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now my server reads all the message from client. Now it is a one
Now I have another problem with WCF server/client. I have a method: bool spr_wiersz(int
Now on writing path as sys.path.insert(0,'/home/pooja/Desktop/mysite'), it ran fine asked me for the word
Now I'm trying to display the result of consuming a webservice from one page
Now that it is possible to make non-container-bound webapps, it would make sense to
now i have such structure on my server ./site.com/ ./site.com/mage ./site.com/mage/Mage.php ./site.com/mage/app ......... ./site.com/public
Now i want to make filter but i really don't know how to do
Now my problem is not one but two, which are as follows: App Requirement:
Now I'm not sure if this is something I'm doing wrong, or something thats
now i'm working on a project for creating audio unit instrument that provide the

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.