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

  • Home
  • SEARCH
  • 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 7524905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:11:15+00:00 2026-05-30T03:11:15+00:00

So I am writing a multithreaded server which takes in as an input the

  • 0

So I am writing a multithreaded server which takes in as an input the server name, port, number of threads, and a file name to request.. My design is to create a socket through main and then extend a Runnable object (which takes in a socket and the file name).. I also have a timertask which fires when 5 seconds are over and then closes and stops all threads.. My current design is to create the socket in main, pass it to runnable (where there is a while loop on condition x, requesting the file over and over), and then when the task fires up it sets the private shared variable x in runnable to false.

I am facing a lot of broken pipe issues which leads me to believe my design is flawed.. Am I missing something? I am not using synchronized/locked variables. Should I create a new socket for every file request?

Stacktrace:

java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:115)
    at java.io.DataOutputStream.writeBytes(DataOutputStream.java:259)
    at FR.filesRecv(Client.java:62)
    at FR.run(Client.java:79)
    at java.lang.Thread.run(Thread.java:637)
  • 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-30T03:11:18+00:00Added an answer on May 30, 2026 at 3:11 am

    Some general comments:

    • Yes, each client should have their own socket connection to the server.
    • On the server side, there is a server socket but when a connection is accepted from a client, a new socket is created for each handler to talk to its corresponding client.
    • I would fork the threads in main and then just sleep for 5 seconds and then set the runnable variables to be false. No need for the timer-task.
    • You can then either exit immediately from main if you want the JVM to stop quickly or you can call join() on each of your threads to make sure they finish appropriately. You can also set thread.setDaemon(false); before the thread starts and then exit main and the JVM won’t stop until the threads finish on their own.
    • You need to make sure that the runnable variable is volatile if it is going to be set from another thread.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a multithreaded client that uses an IO Completion Port. I create
I am writing a multithreaded socket application in Python using the socket module. the
Is I am looking at writing a multithreaded tcp server using boost ASIO. I
I am writing a multi-threaded server, which contains 5 or 6 global data structures
I have the following problem: I have a multithreaded server-side application, where every request
We have a WinForms desktop application, which is heavily multithreaded. 3 threads run with
When writing multithreaded applications, one of the most common problems experienced is race conditions.
I am writing a simple multithreaded socketserver and I am wondering how best to
I'm writing a multi-threaded server using boost::asio (for sockets), boost::thread (for threading), libconfig++ (for
I am currently writing a multi-threaded C++ server using Poco and am now at

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.