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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:28:32+00:00 2026-06-12T11:28:32+00:00

I have Simple web client written on Java and I have to count the

  • 0

I have Simple web client written on Java and I have to count the number of bytes that it sends and recieves. Then I have to compare results with netstat -s command. Also, how can i measure average size of the packets I sent and receive.
Here is WebClient.java:

package javaapplication1;

/**
 *
 * @author
 */
import java.net.*;
import java.io.*;
import java.util.*;

public class WebClient {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter host name (e.g., www.ouhk.edu.hk): ");
        String host = scanner.nextLine();
        System.out.print("Enter page (e.g., /index.html): ");
        String page = scanner.nextLine();
        final String CRLF = "\r\n"; // newline
        final int PORT = 80; // default port for HTTP

        try {
            Socket socket = new Socket(host, PORT);
            OutputStream os = socket.getOutputStream();
            InputStream is = socket.getInputStream();
            PrintWriter writer = new PrintWriter(os);
            writer.print("GET " + page + " HTTP/1.1" + CRLF);
            writer.print("Host: " + host + CRLF);
            writer.print(CRLF);
            writer.flush(); // flush any buffer
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is));
            String line;
            while ((line = reader.readLine()) != null){
                            System.out.println(line);

            }
            System.out.println("Recieved bytes:");
            socket.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
}
  • 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-06-12T11:28:34+00:00Added an answer on June 12, 2026 at 11:28 am

    You could create your own implementations of FilterInputStream and FilterOutputStream that will count all data passed through. Then just use them as filters, for example:

        OutputStream os = new CountingOutpurStream(socket.getOutputStream());
        InputStream is = new CountingInputStream(socket.getInputStream());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple app that uses the C# Web Client class to download
I am writing an app that’s a very simple web service client. I have
I have a simple web client in c# .Net framework 3.5 that calls a
I have created my web socket server and client using this simple tutorial here
I have a simple web browser embedded in an application that allows a user
I have a simple web service that uses an oracle database. When I test
I have a simple web service that has an API third party developers are
I have written a simple HelloWorld web service. Which takes an ArrayList as parameter.
I have a web-application written on ASP.NET MVC 3. On client side I used
I have written a simple service that uploads & downloads XML files. I want

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.