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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:35:09+00:00 2026-05-20T23:35:09+00:00

I wrote a server-client communication program and it worked well. Client module import java.io.*;

  • 0

I wrote a server-client communication program and it worked well.

Client module

import java.io.*;
import java.net.*;

class Client {
    public static void main(String argv[]) throws Exception {
        String sentence;
        String modifiedSentence;
      while(true){
        BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

        Socket clientSocket = new Socket("myname.domain.com", 2343);

        DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

        System.out.println("Ready");
        sentence = in.readLine();
        out.writeBytes(sentence + '\n');
        modifiedSentence = in.readLine();
        System.out.println(modifiedSentence);
       }
      clientSocket.close();
    }
}

Server module

import java.net.*;

public class Server {
    public static void main(String args[]) throws Exception {
        String clientSentence;
        String cap_Sentence;
        ServerSocket my_Socket = new ServerSocket(2343);

        while(true) {
            Socket connectionSocket = my_Socket.accept();
            BufferedReader in = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
            DataOutputStream out = new DataOutputStream(connectionSocket.getOutputStream());
            clientSentence = in.readLine();
            cap_Sentence = "Raceived:" +  clientSentence + '\n';
            out.writeBytes(cap_Sentence);
        }
    }
}

The above is the code for a single client – server communication, now I want multiple client to interact with that server. I googled for it and found that it can be done with the use of a thread for each single client to talk to the server, but since I am a beginner I don’t know exactly how to implement. So somebody please tell me how to do or give me some idea about it.

  • 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-20T23:35:10+00:00Added an answer on May 20, 2026 at 11:35 pm

    MainServer class

    public class Server {
    
        public static void main(String[] args) throws IOException {
    
            ServerSocket serverSocket = null;
    
            boolean listeningSocket = true;
            try {
                serverSocket = new ServerSocket(2343);
            } catch (IOException e) {
                System.err.println("Could not listen on port: 2343");
            }
    
            while(listeningSocket){
                Socket clientSocket = serverSocket.accept();
                MiniServer mini = new MiniServer(clientSocket);
                mini.start();
            }
            serverSocket.close();       
        }
    
    }
    

    Helper Class

    public class MiniServer extends Thread{
    
        private Socket socket = null;
    
        public MiniServer(Socket socket) {
    
            super("MiniServer");
            this.socket = socket;
    
        }
    
        public void run(){
                //Read input and process here
        }
                //implement your methods here
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I've got an Open Source Java client/server program that uses packets to
I start to write a client - server application using .net (C#) for both
I am using C# .Net 2.0 to write a webservices client. The server's soap
I am new to java NIO. I have to write a simple server client
I wrote two applictions which comunicate by socket. This is the code: Server: import
I write a comunication program with c/s mode in C# ,server and client program
Everything is in the question. I wrote an UDP server/client and I want to
I try to write a simple client/server application (all application is a bluetooth service
I wrote an application server (using python & twisted) and I want to start
I'm creating a networked server for a boggle-clone I wrote in python, which accepts

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.