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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:05:13+00:00 2026-05-25T15:05:13+00:00

I am trying to implement a chatserver with using GUI components. I implemented 3

  • 0

I am trying to implement a chatserver with using GUI components. I implemented 3 parts(Server,Client and GUI components).

Following are a few problems I have –

  • I can’t wrap the code with GUI code.
  • When talking with clients, it only works when everybody enter only one line and press enter.

Code:

First GUI component:

public class ChatServer extends javax.swing.JFrame {
    String str;

    public ChatServer() {
        initComponents();      
        screen.setEditable(false);
    }

private void sendActionPerformed(java.awt.event.ActionEvent evt) {                                     
    str = enter.getText();
    enter.setText("");
    screen.append(str+"\n");

}

public static void main(String args[]) {
        new ChatServer().setVisible(true);
}

    private javax.swing.JTextPane enter;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea screen;
    private javax.swing.JButton send;

}

and it looks like:

enter image description here

This my server code:

public class Server {
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(23);
        System.out.println(InetAddress.getLocalHost()+" hazir");
        while(true){
            Socket s = ss.accept();
            System.out.println(s.getInetAddress().getHostName() + " baglandi");
            new ServerPart(s).start();
        }
    }

}

public class ServerPart extends Thread {
    private Socket s;
    public ServerPart(Socket s){
        this.s=s;
    }

    @Override
    public void run() {

        try {

            PrintStream ps = new PrintStream(s.getOutputStream());

            ps.println("Hello" + s.getInetAddress().getHostName());

            String gelen;

            while(true){ 

            Scanner sc = new Scanner(s.getInputStream());   

            gelen = sc.nextLine();

            if(gelen.trim().equalsIgnoreCase("bye"))
                break;


            System.out.println("Client: " + gelen);

            BufferedReader input = new BufferedReader( 
                    new InputStreamReader(System.in) );

            ps.println("Server: " + input.readLine());

            }

            s.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
}

Client code:

public class Client extends Thread {
    private Socket s;
    public Client(Socket s){
        this.s=s;
    }

    @Override
    public void run() {
        try {

            PrintStream ps = new PrintStream(s.getOutputStream());

            Scanner sc = new Scanner(s.getInputStream());

            ps.println("Hello" + s.getInetAddress().getHostName());

            String gelen;

            while(true){

                BufferedReader input = new BufferedReader( 
                        new InputStreamReader(System.in) );

            gelen = sc.nextLine();

            if(gelen.trim().equalsIgnoreCase("bye"))
                break;

            System.out.println("Client: " + gelen);
            ps.println("Server: " + input.readLine());


            }

            s.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

    /**
     * @param args
     * @throws IOException 
     * @throws UnknownHostException 
     */
    public static void main(String[] args) throws UnknownHostException, IOException {

        Socket s = new Socket("192.168.1.173", 23);

        new Client(s);

    }

}

Would appreciate if you can help me mates.

  • 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-25T15:05:13+00:00Added an answer on May 25, 2026 at 3:05 pm

    You are using PrintStream class , with method ps.readline();. If you are developing a chat application, then this approach will not work, as readline method terminate the stream when found newline or End of file, or when carriage return i.e. enter. So I do prefer to use.. datainputstream and dataoutputstream —

    Socket sc = new Socket("address",port);
    DataOutputStream daos;
    DataInputStream dis;
    dis = new DataInputStream(sc.getInputStream());
    daos= new DataOutputStream(sc.getOutputStream());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to implement simple secured client server communiction using WCF. when im launching
Trying to implement the following behavior on an iPad. I have a map-centric application
Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
trying to implement a dialog-box style behaviour using a separate div section with all
I am trying to make a simple Client-Server application but when I execute the
Im trying to implement a single aspx page with several externals dll's. Following Zimmergren's
Im trying to implement fade in effect to my mp3 player. I´m using FloatControl
I'm trying to implement Simple chat using Servlet 3.0 and Comet pattern based on
Trying to implement what I thought was a simple concept. I have a user
Trying to implement the following structure from c to use NSArray in objective-c: In

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.