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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:07:13+00:00 2026-05-29T07:07:13+00:00

Hi i want to test if my client app is working by testing it

  • 0

Hi i want to test if my client app is working by testing it on a very simple java server. My client will send a string almost every second. My idea is that the server will display the string in the eclipse console once it receives the string. But the problem is that the simple java server only prints out the first string. Below is the simple java server i got from the site

  package serverjava;

/* ChatServer.java */
import java.net.ServerSocket;
import java.net.Socket;

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class serverjava {
    private static int port = 1234; /* port the server listens on */

    public static void main (String[] args) throws IOException {
        ServerSocket server = null;
        try {
            server = new ServerSocket(port); /* start listening on the port */
        } catch (IOException e) {
            System.err.println("Could not listen on port: " + port);
            System.err.println(e);
            System.exit(1);
        }

        Socket client = null;
        try {
            client = server.accept();
        } catch (IOException e) {
            System.err.println("Accept failed.");
            System.err.println(e);
            System.exit(1);
        }

        /* obtain an input stream to the client */
        BufferedReader in = new BufferedReader(new InputStreamReader(
                    client.getInputStream()));

        String msg;
        /* loop reading lines from the client and display them */
        while ((msg = in.readLine()) != null) {
            System.out.println("Client says: " + msg);
        }
    }
}

Is the java server capable of displaying only an instance of a string per launch? If yes, how can I make it to print or show in the console all the strings that are being sent every second?

  • 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-29T07:07:16+00:00Added an answer on May 29, 2026 at 7:07 am

    The problem you have is that you read the buffer only one time. The server waits for client lines and when it reads them, then it finish the execution because ‘msg’ is null. You must have a process that reads every second or minute, or hour… That means using THREADS.

    • If you want to see more examples, go here:
      http://www.isr.umd.edu/~austin/ence489c.d/threads.html.
    • And here you have some information:
      http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html

    Be careful! Don’t use a while(true) structure of something like that, because the machine will be overloaded.

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

Sidebar

Related Questions

I am writing a simple UDP-based client/server app and testing with both the client/server
I want to write a simple P2P test app which uses HTTP as underlying
I have a Java rich client desktop app. that I want to distribute on
I am trying to write a simple tcp client/server app that copies a file.
I'm working with some client on making an app. I managed to get him
I'm testing calling a SOAP based service from a .net client app and am
I'm trying to access the request.user object when testing my app using django's client
I'm writing a short test app to practice connecting to a server. All the
I've written a small hello world test app in Silverlight which i want to
A client noticed that one of our java applets wasn't working anymore. However, we

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.