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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:51:18+00:00 2026-05-28T04:51:18+00:00

i have a java chat server & client, that works fine. I made a

  • 0

i have a java chat server & client, that works fine. I made a server to client file transfer program separately, it is also working fine. But when i try to integrate the file transfer into chat, the file is getting transferred, but during that time, the chat program just freezes, so much that i can’t even type a thing into the chat box, and when transfer gets over, things get normal. how to make it normal, like chatting and file transfer is taking place side by side, none gets affected by the other?

My file transfer has while loops on both server and client, i wanted to know that is this because of while loops, should i create threads on both file transfer’s server and client code.
My Chat System is like, on server,user connects, threads starts on server for that user, for reading from user, it then sends these messages from user to everyone.
On client, threads are for reading from server, when user types messages, it send it to server, which then return messages to everyone connected.

i think the problem is on Client side, as i just tested this on internet with my friend, i was the server, for both Chat & File Transfer, my chat box was fine, i was able to type, but his chat client freezd for the time file transfer took place.

i don’t know which part of code is causing this, so i’ll update this with code, as soon as someone asks for it..

Thanks,
Any help wud be appreciated.

[EDIT–FILE TRANSFER ON CLIENT]

public class FileClient{


JFrame jfr;
JTextField Jtf = new JTextField(4);
public static void main (String [] args ) {

 // new FileClient().go();

 }

public void go(String ip){
    try{
    JFrame jfr = new JFrame("File Transfer");
            JPanel panel = new JPanel();
    JLabel jl = new JLabel("Progress:");
    jfr.getContentPane().add(BorderLayout.CENTER,panel);
    panel.add(jl);
    panel.add(Jtf);
    Jtf.setEditable(false);
    jfr.setSize(200,70);
    jfr.setVisible(true);
    jfr.setDefaultCloseOperation(jfr.EXIT_ON_CLOSE);
}catch(Exception e){e.printStackTrace();}
long start = System.currentTimeMillis();
    int read;
    int totalRead = 0;
    try{
    Socket sock = new Socket(ip,4243);
    System.out.println("Connecting...");
    InputStream is = sock.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(new ProgressMonitorInputStream(jfr,"reading",is));

    byte [] mybytearray  = new byte [512];
    int buff =1024;
    byte[] nameByte = new byte [50];
    byte[] nameByteSize = new byte [2];
    byte[] Size = new byte [10];
    byte[] SizeSize =new byte [1];

    int num = is.read(nameByte,0,50);
    int nameSize = is.read(nameByteSize,0,2);
    int sz = is.read(Size,0,10);
    int yy = is.read(SizeSize,0,1);
    float w;

    String Size1 = RemoveNameStuffing(new String(Size),new String(SizeSize));
    int tt = Integer.parseInt(Size1);
    System.out.println("tt"+tt);
     name"+new String(nameByte));
    String name = RemoveNameStuffing(new String(nameByte),new String(nameByteSize));
    File f1=new File(name);

    FileOutputStream fos = new FileOutputStream(f1);
    BufferedOutputStream bos = new BufferedOutputStream(fos);

    while ((read = bis.read(mybytearray,0,mybytearray.length)) != -1) {
            bos.write(mybytearray, 0 , read);
            totalRead += read; 
            w=((float)totalRead/tt)*100;
            System.out.println("progress:"+w+"%");
            Jtf.setText(w+"%");
    }


    bos.flush();
    long end = System.currentTimeMillis();
    System.out.println(end-start);
    bos.close();
    sock.close();
    }catch(IOException e){e.printStackTrace();}
}

public static String RemoveNameStuffing(String s, String n){

    s=s.substring(0,Integer.parseInt(n));
    System.out.println("s:"+s);

    return s;

}

}

[EDIT–THIS IS HOW I AM CALLING FILE TRANSFER CODE INTO CHAT CLIENT]

public class AcceptFileButtonListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
      FileCl.go(JTip.getText());
    }

}

[EDIT–FILE TRANSFER SERVER CODE–BUFFER SIZE 512]

//Waiting for connection
//Sending name in bytes
//While{
   send files as bytes
   }

[CHAT SERVER WHERE ABOVE (FT SERVER) CODE IS CALLED]

public void actionPerformed(ActionEvent e) {

        FileSv.go();

    }

and my server also freezes as soon as i press the button, even when the FT server has not even got a connection(i think this cud help).

i have a chat server and client, both having threads to read from each other. i tried to integrate my File transfer server and client into existing chat server and chat client.
initially when user connects to chat server, it starts a thread for it. now to send a file to that user, i created 1 button on server(file send) and 1 on client(accept file), now as i click onto “file send” on server, my File transfer server code gets executed, and File transfer Sever wait for a connection on different port(my chat server now freezes, it has a textField, which is unresponsive now), now if the user with whom i am chatting perfectly, clicks on “accept file” File transfer client code gets executed. FT server starts sending bytes, FT client rcvs it. both the server and client CHAT window becomes unresponsive for the time transfer takes place, and whatever i have sent from the client side chat box during transfer, gets updated after transfer.
This is to clear the confusion. even if this doesn’t help, i will upload whole code(which is too big)

  • 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-28T04:51:19+00:00Added an answer on May 28, 2026 at 4:51 am

    Ok, to expand my comment – you say when clicked on a button on the clientchat window, FileTransferClient side is initiated, which works on while loop to read byte from server.

    Are you running your file transfer code in the Swing Event thread? If so, you need to wrap it inside a Runnable object, ensure that its yielding up some processing time between iterations of the while loops, and invoke it using SwingUtilities.

    If you’re starting a separate thread on the button press in order to transfer the file, you still need to yield up processing time between loops of your sending loop or you’re not yielding any processing time to the chat processing threads.

    edit: amend your action listener call to do the following:

     @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
      SwingUtilities.invokeLater(
          new Runnable() { 
             public void run() {
                FileCl.go(JTip.getText());
             }
          }
       );
    }
    

    What this does is move the CPU and IO intensive processing of your file download into a new thread, external to the Swing event thread.

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

Sidebar

Related Questions

I have implemented a chat service and desktop client using Java, the program works
I have written a chat server that works with telnet. I wrote a client
I have 2 threads running a chat program such that one is a server
I'm building a simple chat server in java , where users can have private
I have an app that connects to a remote chat server and then the
I have developed a basic Chat application in Java. It consists of a server
I am working on a java program that is essentially a chat room. This
I'm trying to make a simple chat server in Java. Now I have a
FYI This is homework. I have to build a Java Chat server. I have
I have a multi-threaded server that handles client requests, and makes new threads for

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.