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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:39:02+00:00 2026-05-30T16:39:02+00:00

Update – Moving to consistent type provided solution Client sends message to server socket,

  • 0

Update – Moving to consistent type provided solution

Client sends message to server socket, the server then responds to the client with original message. When introducing the latter functionality, the server only receives one message rather than continuing to receive said messages, and does not respond to client. Commented on lines that were added. Any insight into hangup would be great.

Client side, issues commented and code update from responses:

{  private Socket socket              = null;
   private BufferedReader  console   = null;
   private DataInputStream  streamIn   = null;
   private DataOutputStream streamOut = null;

  while (!line.equals(".bye"))
  {  try
     {  line = console.readLine();
        streamOut.writeUTF(line); //Send console data to server socket
        String reply = streamIn.readUTF(); //Recieve confirmation msg from server
        System.out.println( reply ); //Print the msg
        streamOut.flush();
     }

   public void start() throws IOException
   {  console = new BufferedReader(new InputStreamReader(System.in)); //Changed console to BufferedReader
      streamIn  = new DataInputStream(socket.getInputStream());
      streamOut = new DataOutputStream(socket.getOutputStream());
   }
   public void stop()
   {  try
      {  if (console   != null)  console.close();
         if (streamOut != null)  streamOut.close();
         if (streamIn != null)  streamIn.close(); //Is it good practice to close
         if (socket    != null)  socket.close();
      }

Server side, issues commented.

   public void handleClient() throws IOException {
      boolean done = false;
      try {
      System.out.println("Server Thread " + ID + " running.");
      while (!done) {
        String nextCommand = streamIn.readUTF();
        if( nextCommand.equals(".bye") ) {
           System.out.println("Client disconnected with bye.");
           done = true;
        } else {
           System.out.println( nextCommand );
           String nextReply = "\"You sent me ->" +nextCommand.toUpperCase() + "\"\n";
           streamOut.writeUTF( nextReply );
        }
     }
   } finally {
     streamIn.close();
     streamOut.close();
     socket.close();
   }
   }
   public void open() throws IOException
   {
      streamIn = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
      streamOut = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
//      streamOut = new DataOutputStream(socket.getOutputStream());
  }
   public void close() throws IOException
   {  if (socket != null)    socket.close();
      if (streamIn != null)  streamIn.close();
      if (streamOut != null) streamOut.close();
   }
  • 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-30T16:39:03+00:00Added an answer on May 30, 2026 at 4:39 pm

    You are using writeUTF and readUTF but in one place streamIn.readLine() which I would expect to block as it waits for a new line. I suspect you need to use readUTF consistenly.

    BTW the console is not a data stream, its text and I suggest you use BufferedReader.

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

Sidebar

Related Questions

Update 2018 TL;DR; LaTEX for WPF https://github.com/ForNeVeR/wpf-math Original question I need to have a
UPDATE: I now have a solution I'm much happier with that, whilst not solving
UPDATE users SET field = my_sp() in SQL Server 2005. Apparently I can't do
UPDATE : The issue was col1 was hiereachyid type and even a select didnt
Update: Edited code example to use AutoA for the workaround (which was the original
[UPDATE] Was just an idiot mistake. See end for solution. I am trying to
Update: -[NSIndexPath row]: message sent to deallocated instance 0x895fe70 When I run my app
UPDATE: Solution at bottom. I recently switched from using a set up such as
Update : I found the solution by removing v.setFocusable(true); v.setClickable(true); in the code and
Update: Solved, with code I got it working, see my answer below for the

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.