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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:08:01+00:00 2026-06-07T13:08:01+00:00

I was typing a question but finally I solved the problem and don’t wanted

  • 0

I was typing a question but finally I solved the problem and don’t wanted to toss it (and encouraged by https://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/), and decided to share my problem-solution.

The problem is that I want to retrieve some bytes from a Java application server, that means, via a Servlet to load in a flash game for a replay feature.

There are some questions trying to solve the other way problem, that means, from as3 to a server (php, java, etc): How to send binary data from AS3 through Java to a filesystem?, How can I send a ByteArray (from Flash) and some form data to php?, Uploading bytearray via URLRequest and Pushing ByteArray to POST. I didn’t find something like what I’m sharing (correct me if I’m wrong).

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

    Well, as I said in the question, I was encouraged by StackOverflow to answer and here it is:

    The Servlet doGet method that gives the byte array:

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
    
       MouseInput oneInput = getMouseInput(); //abstracted (I'm using google appengine)
       byte[] inputInBytes = oneInput.getInBytes();
       OutputStream o = resp.getOutputStream();
       o.write(inputInBytes);
       o.flush();
       o.close();
    }
    

    MouseInput.getInBytes method body:

       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       DataOutputStream dos = new DataOutputStream(baos);
    
       dos.writeInt(this.type);
       dos.writeDouble(this.localX);
       dos.writeDouble(this.localY);
       dos.writeBoolean(this.buttonDown);
    
       return baos.toByteArray();
    

    My Actionscript code to receive the byte array data:

    var url:String = "http://localhost:8888/input"; //servlet url
    var request:URLRequest = new URLRequest(url);
    
    //get rid of the cache issue:
    var urlVariables:URLVariables = new URLVariables();
    urlVariables.nocache = new Date().getTime();
    request.data = urlVariables;
    request.method = URLRequestMethod.GET;
    
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.BINARY;
    
    loader.addEventListener(Event.COMPLETE, function (evt:Event) {
        var loader:URLLoader = URLLoader(evt.target);
    
        var bytes:ByteArray = loader.data as ByteArray;
        trace(bytes); //yeah, you'll get nothing!
    
        //the bytes obtained from the request (see Servlet and 
        //MouseInput.getInBytes method body code above) were written in 
        //the sequence like is read here:           
        trace(bytes.readInt());
        trace(bytes.readDouble());
        trace(bytes.readDouble());
        trace(bytes.readBoolean());
    }
    loader.addEventListener(IOErrorEvent.IO_ERROR, function (evt:Event) {
        trace("error");
    });
    
    loader.load(request);
    

    Well, it works! Obviously you can make some adjustments, like not using the anonymous function for better reading, but to illustrate it was ok! Now I can save some memory to a game replay feature (for debug purpose) with ByteArray instead of heavy XML that I was trying.

    Hope it helped and any critics is appreciated!

    Cheers

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

Sidebar

Related Questions

I started with a question, and in typing the question, found the answer, but
Sort of a continuation from an earlier question, done a bunch of googling, but
A newbie question but..... I've installed python2.7 on a host where the system version
Apologies if I've framed the question incorrectly but I'm not sure where it fits
A similar question was asked elsewhere, but the answer doesn't seem to work in
I apologize if this is a dumb question, but hear me out: Dictionary<string, string>
I'm sorry if this is a stupid question, but I'm very new to Matlab,
NOTE This was flagged as a potentially subjective question, but it is not subjective.
I've asked this question before but I didn't seem to get the right answer.
I've seen this question asked in .asp threads but I'm not using .asp so

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.