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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:26:10+00:00 2026-05-20T15:26:10+00:00

OK so at the moment I am trying to create an Android Game, I

  • 0

OK so at the moment I am trying to create an Android Game, I have a Thread running which is fine.

However I am unsure of how to determine how big the incoming buffer size, and how to read it.

Currently this is my code:

        if(!thisPlayer.isHost)
        {

            byte[] incMsg = new byte[64];
            try {
                socket = new DatagramSocket(port);
                //socket.setSoTimeout(10);
                DatagramPacket packet = new DatagramPacket(incMsg, incMsg.length);
                socket.receive(packet);
                Log.d("Receiving Game Message", "Received"+incMsg.toString());
            } catch (UnknownHostException err) {
                Log.e("", "", err);
            } catch (Exception err) {
                Log.e("", "", err);
            }  
            testString = incMsg.toString();
        } else {
            byte[] msg = "Game On".getBytes();
            try {
                String compIP = "192.168.1.102";
                String ip;
                if(thisPlayer.ipAddress.equals(compIP))
                    ip = "192.168.1.107";
                else
                    ip = compIP;
                InetAddress sendingIP = InetAddress.getByName(ip);
                socket = new DatagramSocket(port);
                DatagramPacket p = new DatagramPacket(msg, msg.length, sendingIP, 5130);
                socket.send(p);
                Log.d("Sending Game Message", "Sent");
                socket.close();
            } catch (UnknownHostException err) {
                Log.e("", "",  err);
            } catch (Exception err) {
                Log.e("", "", err);
            } 
        }
        socket.close();

This kind of works. The Host is sending data. The Client is receiving data (I have commented out the sotimeout and the thread continues, so I know its receving data).

I convert the byte[] to a string and then display it. However what is displaying is “[B@448xxxx” where xxxx is a series of repeating numbers/letters.

Unfortunately I am up to the point where I am getting frustrated and now clouded brain, and cannot think for the life of me where I have gone wrong.

TIA

p.s. I have even tried making the receiving byte array the same size as the outgoing, without any luck :/

  • 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-20T15:26:11+00:00Added an answer on May 20, 2026 at 3:26 pm

    As far as I know, this means a pointer to byte array. You can’t just assign it to string, instead, use (new String(inMsg)).
    Also, since you didn’t initialize the array, you’ll receive garbage after your received data (if shorter than the array).

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

Sidebar

Related Questions

I'm new to both android and game development and have been trying to create
At the moment I'm trying to create a kind of model in vb.net which
I'm trying to create a air-hockey game, in flash using AS3. At the moment,
I'm trying to create a game loop using this tutorial . I have tried
I'm trying to create a multiview controller for a game, in which one root
At the moment I am trying to create a setup where page content is
At the moment I'm trying to build some integration tests for an android project.
I'm developing a poker game in C#. At the moment I'm trying to get
I'm trying to create a scrollable layout in Android. Even using developers.android.com, though, I
I am trying to create a procedure which will fill up the table until

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.