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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:12:20+00:00 2026-06-12T13:12:20+00:00

I am writing a web app that runs on tomcat. I need to transfer

  • 0

I am writing a web app that runs on tomcat. I need to transfer around 25 kb of data (all double/long values every 20 ms from server to client.) Trying to use server-sent events for this, as I just need one one way communication channel from server to client.

Using java at server side and java script at client side.

Please suggest if what I am talking here makes sense at all and if it is achievable.

I am new to web development.

  • 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-12T13:12:21+00:00Added an answer on June 12, 2026 at 1:12 pm

    Why don’t you try it yourself – you will notice a big difference between localhost and an actual network:

    Servlet (Generates 25kb big messages):

    import java.io.IOException;
    import java.io.Writer;
    import java.util.Random;
    import javax.servlet.AsyncContext;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    @WebServlet(name = "EventServlet", urlPatterns = {"/EventServlet"}, asyncSupported = true)
    public class EventServlet extends HttpServlet {
    
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            response.setContentType("text/event-stream; charset=utf-8");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Transfer-Encoding", "Chunked");
            response.flushBuffer();
            final AsyncContext ctx = request.startAsync();
            ctx.setTimeout(0);
    
            ctx.start(new Runnable() {
                @Override
                public void run() {
    
                    try {
    
                        Writer out = ctx.getResponse().getWriter();
                        for (;;) {
                            out.write("event: simpleEvent\n");
                            out.write("data:" + randomString(25000) + "\n\n");
                            ctx.getResponse().flushBuffer();
                        }
    
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        ctx.complete();
                    }
    
                }
            });
    
        }
        private static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        private static Random rnd = new Random();
    
        public static String randomString(int len) {
            StringBuilder sb = new StringBuilder(len);
            for (int i = 0; i < len; i++) {
                sb.append(AB.charAt(rnd.nextInt(AB.length())));
            }
            return sb.toString();
        }
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }
    
        @Override
        public String getServletInfo() {
            return "Short description";
        }
    }
    

    Index.jsp:

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
    
            <div>Number of Messages</div>
            <div id="out">
    
            </div>
            <div>Messages per Second:</div>
    
            <div id="mean">
    
            </div>
    
        </body>
    
        <script type="text/javascript">
    
            var startTime = new Date().getTime();
            var counter = 0;
    
            var eventSource = new EventSource("EventServlet");
    
            eventSource.addEventListener('simpleEvent', function(event){
                counter++;
                document.getElementById("out").innerHTML=counter;
    
                var seconds = (new Date().getTime()-startTime)/1000;
                document.getElementById("mean").innerHTML=counter/seconds;
            },false);
    
        </script>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a web-app using Python and Pylons. I need a textbox that is
I'm writing a simple web app that uploads some files to a server, runs
I am writing a Web app that will need to run a background process
We're writing a web app that relies on Javascript/jQuery. It involves users filling out
I'm writing a simple web app in PHP that needs to have write access
I am writing a web app in PHP using mySQL that models an election.
I'm writing a web app that uses an HTML5 canvas and testing on a
I am writing a web app that will use HTML to display a form.
I'm writing a web app that will use twitter as its primary log on
I'm writing a web app that serves H.264 encoded MP4 video. In Chrome and

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.