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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:42:14+00:00 2026-06-15T23:42:14+00:00

I am trying to build a client server chat application using Swing. In that

  • 0

I am trying to build a client server chat application using Swing.

In that when I start client I send a message that I can receive at client site but when I press a button on Server site it will not open up a new Frame (that is in my case error here).

How can I solve it? Can any one suggest me some other way?

My code is (server site):

import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
class Cli extends JFrame
{
   ServerSocket ss;
   Socket soc;
   InputStream in;
   OutputStream out;

   DataInputStream sin;
   DataOutputStream sout;

   JLabel l1;
   JTextField txt1;
   JButton addd;
  Cli()  throws Exception
  {
Class.forName("com.mysql.jdbc.Driver");
Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/nirav","root","root");
JPanel pan=new JPanel(new GridLayout(2,1));
ss=new ServerSocket(8888);
//ss.setSOLimit(10000);
l1=new JLabel("waiting for client");
txt1=new JTextField(40);
addd=new JButton("click here to send");
addd.addActionListener(new ActionListener()
      {
    public void actionPerformed(ActionEvent ae) 
        {   try{
                JOptionPane.showMessageDialog(null,"Data is successfully inserted into the database." );    
                l1.setText("waiting");
                Recieve c=new Recieve();
                c.setSize(300,300); 
                c.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                c.setVisible(true);

                }catch(Exception e)
                {
                System.out.println(e.toString());
                }
            }                               
        }); 
soc=ss.accept();
in=soc.getInputStream();
out=soc.getOutputStream();
sin=new DataInputStream(in);
sout=new DataOutputStream(out); 
String s="";
try{
    s=sin.readUTF();        
    }catch(Exception e)
    {
    }
    l1.setText("client :"+s);
pan.add(l1);
pan.add(txt1);
pan.add(addd);
add(pan);
}
class Recieve extends JFrame
{
JLabel msg;
JTextField t1;
JButton a1;
 Recieve() throws Exception
 {  
JPanel pan=new JPanel(new GridLayout(2,1));
t1=new JTextField(40);
a1=new JButton("click here to send");
//msg=new JLabel("waiting...");
 a1.addActionListener(new ActionListener()
{   public void actionPerformed(ActionEvent ae)
        {   try{
                String s;
                String str="Server :";
                sout.writeUTF(t1.getText());
                //msg.setText(str);
                sout.flush();
            }catch(Exception e)
{
System.out.println(e.toString());
}
}});
pan.add(t1);
pan.add(a1);
add(pan);
   }
   }
  }
 class Server 
{   
  public static void main(String args[]) throws Exception
{
try{

Cli c=new Cli();
c.setSize(300,300);
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setVisible(true);
}
catch(Exception e)
{
System.out.println(e.toString());
}

}
  }
  • 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-15T23:42:15+00:00Added an answer on June 15, 2026 at 11:42 pm

    How are you capturing the message that was sent from the server? You need to implement something that will make usage of your UI listeners to present the updated on the chat windows whenever the application receives data from the server.

    I just did a quick research and found this project, try to use his code as reference to implement your program:
    https://github.com/rafaelsakurai/socket-exemplo-chat-swing

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

Sidebar

Related Questions

I'm trying to build a client server application using POSIX shared memory and POSIX
I'm trying to build a simple echo server/client that works on ethernet level(using raw
I am trying to build a server program that receives file from client using
I'm a hobby programmer trying to build a client/server application suite, using Delphi XE.
I'm trying to test a client/server application, and using Maven to handle the build/test/deploy.
I'm trying to build a server that will receive files sent by clients over
I am trying to build a server side application (PHP) which can download photos
Trying to build a proxy server. recv from client -> send to server ->
I'm trying con build a simple chat client/software (whole in on executable) wich start
I'm trying to build a GWT (2.4.0) application that can communicate (full-duplex) with a

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.