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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:03:06+00:00 2026-05-31T16:03:06+00:00

Im building a simple chat client which is only supposed to be able to

  • 0

Im building a simple chat client which is only supposed to be able to send and receive messages.

Im using a server running on my own computer that sends back whatever message is sent to it, to all the user that’s connected to the server.

When I send messages to the server by clicking my “send button”, the server isn’t sending back the message to me as it’s supposed to. So either my output stream isn’t working, or my listener for input messages isn’t working but can’t figure out what is wrong.

I might add, that i don’t get any error messages/exceptions and connecting to the server works

public class Chatt extends JFrame implements Runnable{
    private JPanel topPanel = new JPanel();
    private JPanel bottomPanel = new JPanel();
    private JTextArea chattArea = new JTextArea();
    private JButton sendButton = new JButton("Skicka");
    private JLabel chattPerson = new JLabel("Du chattar med: ");
    private JTextField chattField = new JTextField(15);
    private Thread thread;
    private int port;
    private String ip;
    private DataInputStream in;
    private DataOutputStream out;
    private Socket s;


    public Chatt(String ip, int port){
        this.ip=ip;
        this.port=port;
        Konstruktor();
        }
    public Chatt(){
        ip="127.0.0.1";
        port=2000;
        Konstruktor();
        }
    public Chatt(String ip){
        this.ip=ip;
        port=2000;
        Konstruktor();
        }

    public void Konstruktor(){
        setLayout(new BorderLayout());

        chattArea.setSize(70, 50);  
        add(chattArea, BorderLayout.CENTER);

        bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
        bottomPanel.add(sendButton);
        bottomPanel.add(chattField);
        sendButton.addActionListener(new sendListener());
        add(bottomPanel, BorderLayout.SOUTH);

        topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
        topPanel.add(chattPerson);
        add(topPanel, BorderLayout.NORTH);

        try {
            //s = new Socket("atlas.dsv.su.se", 9494);
            s=new Socket(ip, port); 
            } 
        catch (UnknownHostException e) {
                System.out.println("Connection failed");
                } 
        catch (IOException e) {
                    }
        try{
        in= new DataInputStream(new BufferedInputStream(s.getInputStream()));
        out= new DataOutputStream(new BufferedOutputStream(s.getOutputStream()));
        }
        catch(UnknownHostException e){
                System.out.println("Host unknown");
            }
        catch(IOException e){

        }
        thread = new Thread(this);
        thread.start();

        setTitle("Connected to "+ip+" på port "+port);
        chattArea.setEditable(false);
        setSize(400, 500);
        setVisible(true);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    public void run() {

            while(true){
                System.out.println("tråden igång");
                try {
                    String temp = in.readUTF();
                    System.out.println(temp);
                    chattArea.append(temp);
                } catch (IOException e) {

                }

            }       
    }


    public class sendListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            String chattString = chattField.getText();
                try {
                    out.writeUTF(chattString);
                    out.flush();
                    } 
                catch (IOException e1) {

                    }
                chattArea.append("Du: "+chattString+"\n");
                chattField.setText("");

            }

    }



    public static void main(String[] args){
        //new Chatt("127.0.0.1", 2000);
        //new Chatt();
        new Chatt("127.0.0.1");
    }

}
  • 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-31T16:03:08+00:00Added an answer on May 31, 2026 at 4:03 pm

    I can confirm that the chatserver wasn’t working correctly. I did build my own server and sending/reciving messages works fine, so nothing wrong with my code.

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

Sidebar

Related Questions

I'm building a simple client-server chat system. The clients send data to the server
I'm building a simple java Servlet which passes categories using a URL variable into
I'm building a simple live chat into a web application running on Django, but
I'm building a simple chat server in java , where users can have private
Well, lets say I'm building ActiveMQ based chat application. It's pretty simple. Having only
I'm building a simple tcp/ip chat program and I'm having difficulty sending messages separately.
I am building a simple client-server program , I have in main : FTPClient
I'm building a simple real time chat using Juggernaut, Redis, SQLite and Rails 3.1
I am building a simple ajax chat client for a school project and have
I'm building a simple Todo List application where I want to be able to

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.