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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:08:49+00:00 2026-05-28T16:08:49+00:00

I have code like this try { ServerSocket serverSocket = null; try { serverSocket

  • 0

I have code like this

try {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(888);
        } catch (IOException e) {}

        Socket clientSocket = null;
        try {
            clientSocket = serverSocket.accept();
        } catch (IOException e) {}

        out = new PrintWriter(clientSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        String inputLine, outputLine;

        while ((inputLine = in.readLine()) != null) {
            outputLine = "SRV:>"+inputLine+"<:VRS";
            out.println(outputLine);
            taWyjscie.append(outputLine+"\n");
            if (inputLine.equals("Bye."))
                break;
        }

        out.close();
        in.close();
        clientSocket.close();
        serverSocket.close(); 

    } catch (IOException ex) {
        taWyjscie.append("Błąd I/O: "+ex.getLocalizedMessage() + "\n");
    }

It works, but app is unusable until client sends “Bye.”.

I want to be able to send messages to client from server by gui, so im fighting with SwingWorker, i got this:

try {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(888);
        } catch (IOException e) {}

        Socket clientSocket = null;
        try {
            clientSocket = serverSocket.accept();
        } catch (IOException e) {}

        out = new PrintWriter(clientSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        String inputLine, outputLine;

        zadanie = new ServerTask(in);

    } catch (IOException ex) {
        taWyjscie.append("Błąd I/O: "+ex.getLocalizedMessage() + "\n");
    }

 private class ServerTask extends SwingWorker<String, String> {
    private BufferedReader iin;

    public ServerTask(BufferedReader win) {
        this.iin = win;
    }


    @Override
    protected String doInBackground() throws Exception {
        String input;
        while ((input = iin.readLine()) != null) {
            System.out.println(input);
            publish(input);
            if (isCancelled())
                break;
        }
        return null;
    }
    @Override
    protected void process(List<String> chunks) {
        for(String el : chunks) {
            textAreaOUT.append(el+"\n");
        }
    }

}

now i cant send message from server to client, but messages from client are not displayed in textArea. Im fighting with since morning and i cant get idea how swingworker is working…

PS. this try … catch in front is in button actionperformed function (if it makes any differece)

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

    You never call execute on your SwingWorker, thats your first bug. Start there..

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

Sidebar

Related Questions

I'm new to Django and have some code in my views.py like this: try:
If I have code like this: try { Thread t = new Thread(new ThreadStart(wc.LocalRunProcess));
I have code like this try { header(Location: http://www.google.com\n-abc); } catch (Exception $e) {
I have a code like this: try { using (TransactionScope scope = new TransactionScope())
I have a C++ DLL with code like this: LogMessage( Hello world ); try
I have code like this: var newMsg = new Msg { Var1 = var1,
I have code like this: string uriString = @C:\Temp\test.html; Uri uri = new Uri(uriString);
I have code like this: MediaElement me = myPlayer.MediaElement; WriteableBitmap wb = new WriteableBitmap(me.NaturalVideoWidth,
I have a code like this. DBContext is Datacontext instance. try { TBLORGANISM org
I have some code in a powershell function that looks like this: try {

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.