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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:36:23+00:00 2026-05-30T12:36:23+00:00

The socket server listed in step 3 from http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html builds cleanly (java version 1.7.0_02)

  • 0

The socket server listed in step 3 from http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html builds cleanly (java version “1.7.0_02”) and runs without error but it exits without error instead of waiting to accept clients.

Updated ChatServer with missing arg code:

ChatServer:

import java.net.*;
import java.io.*;

public class ChatServer implements Runnable
{  private ServerSocket     server = null;
   private Thread           thread = null;
   private ChatServerThread client = null;

   public ChatServer(int port)
   {  try
      {  System.out.println("Binding to port " + port + ", please wait  ...");
         server = new ServerSocket(port);
         System.out.println("Server started: " + server);
         start();
      }
      catch(IOException ioe)
      {  System.out.println(ioe); }
   }
   public void run()
   {  while (thread != null)
      {  try
         {  System.out.println("Waiting for a client ...");
            addThread(server.accept());
         }
         catch(IOException ie)
         {  System.out.println("Acceptance Error: " + ie); }
      }
   }
   public void addThread(Socket socket)
   {  System.out.println("Client accepted: " + socket);
      client = new ChatServerThread(this, socket);
      try
      {  client.open();
         client.start();
      }
      catch(IOException ioe)
      {  System.out.println("Error opening thread: " + ioe); }
   }
   public void start() {
   thread = new Thread(this);
   thread.start();
 }
   public void stop()                    { /* no change */ }
   public static void main(String args[]) {
      ChatServer server = null;
      if (args.length != 1)
         System.out.println("Usage: java ChatServer port");
      else
         server = new ChatServer(Integer.parseInt(args[0]));
 }
}

ChatServerThread:

import java.net.*;
import java.io.*;

public class ChatServerThread extends Thread
{  private Socket          socket   = null;
   private ChatServer      server   = null;
   private int             ID       = -1;
   private DataInputStream streamIn =  null;

   public ChatServerThread(ChatServer _server, Socket _socket)
   {  server = _server;  socket = _socket;  ID = socket.getPort();
   }
   public void run()
   {  System.out.println("Server Thread " + ID + " running.");
      while (true)
      {  try
         {  System.out.println(streamIn.readUTF());
         }
         catch(IOException ioe) {
            System.out.println(ioe.getMessage());
         }
      }
   }
   public void open() throws IOException
   {  streamIn = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
   }
   public void close() throws IOException
   {  if (socket != null)    socket.close();
      if (streamIn != null)  streamIn.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-30T12:36:24+00:00Added an answer on May 30, 2026 at 12:36 pm

    EDIT: Updating my answer with a working solution.

    Change these methods in your ChatServer class in order to be like these

    public void start() {
        thread = new Thread(this);
        thread.start();
    }
    
    public void stop() { 
        // You should implement this too
    }
    
    public static void main(String args[]) { 
        // Instantiate a CharServer with the listening port 9191
        ChatServer chatServer = new ChatServer(9191);
        // CharServer.start() should not be confused with Thread.start();
        // This calls our custom method up above, which includes a call to
        // Thread(ChatServer).start();
        chatServer.start();
    
    }
    

    Where 9191 is a port number I made up.

    Executing CharServer#main method produces the following output and stays alive

    Binding to port 9191, please wait  ...
    Server started: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=9191]
    Waiting for a client ...
    Waiting for a client ...
    

    You should also implement stop() method for the sake of functionality.

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

Sidebar

Related Questions

I've got a socket server running (it's something that's basically like a chat server).
I'm looking for a python socket server framework - not to handle http, but
Hello i made a php socket server to get data from plc, plc is
If I kill the Socket Server process, my Socket client process does not receive
I am developing a socket server where a client will be bound after being
We are writing a socket server in c# and need some advice on the
I'm trying to implement a socket server that will run in most shared PHP
Can we create a Silverlight Socket Server ONLY using SILVERLIGHT and XML's (NO WCF
How to create simple C# Binary socket server (Not WCF!) Who knows the Simplest
I'm currently trying to implement a socket server that enables the clients to send

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.