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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:58:24+00:00 2026-06-17T21:58:24+00:00

I am programming a socket server in Java for an MMORPG in AS3. I

  • 0

I am programming a socket server in Java for an MMORPG in AS3. I have some problems with strange behaviour of HashMap.get(byte[]).
What things could cause the following problem?

I don’t use any serialization system, I send bytes and both client and server knows what to do with what bytes of the received bytes. The first request the client makes is asking the server to create a playing session. The server will generate a random session token as byte[] with 8 entries and adds the token to the HashMap. The response will be 9 bytes long. The first one defines the response type (in this case byte ‘+’ which means “You have been accepted. Here is your token.”) and byte 2-9 are the token. The client must store the token and append it to any further request (This concept can be compared with PHP sessions).

This is the code for adding the client to the HashMap:

byte[] token = Util.generateToken();

// f is ResultSet entry of JDCB SQL query return value
Client client = new Client(f.getInt("id"), token);
Core.clients.put(token, client);

// I display client.token instead of token to make sure client != null      
Log.log("User " + f.getString("name") + " has logged in with session token " + Util.getHexString(client.token) + ".");

Log:

[01:50:30] User has logged in with session token 92:B7:F8:C6:4B:53:17:3A.

These are some debug lines that will displayed at any further request:

// Show (byte[]) Token as Hex String, 8 bytes long
Log.soc("Token: " + Util.getHexString(buffer.getBytes(1, 9)));

// Show all keys in (HashMap<byte[], client>) Core.clients
int it = 0;
for (byte[] b : Core.clients.keySet())
Log.soc("Key Core.clients #" + StringUtils.leftPad(String.valueOf(++it), 2, '0') + " = " + Util.getHexString((b)));

// Display availability bool to make sure
Log.soc(Core.clients.containsKey(buffer.getBytes(1, 9)));

// Get Core.clients value where key = Token
Log.soc("Client: " + Core.clients.get(buffer.getBytes(1, 9)));

Log:

[01:51:09] Token: 92:B7:F8:C6:4B:53:17:3A

[01:51:09] Key Core.clients #01 = 92:B7:F8:C6:4B:53:17:3A

[01:51:09] false

[01:51:09] Client: null

So, how could I find out what’s going 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-17T21:58:25+00:00Added an answer on June 17, 2026 at 9:58 pm

    A HashMap uses hashCode() and equals() to find the entry from a given key. And a byte array will only ever be equal to itself. It won’t be equal to another byte array, even if this other byte array has the same length and the same bytes. You should wrap the arrays inside a Key class which override equals() and hashCode() to make that work.

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

Sidebar

Related Questions

i have written simple client server socket programming code as follow MyServer.java import java.io.DataInputStream;
I am doing socket programming. I have two files called Server.java and client.java. Both
I have spent some time learning about socket programming in Java and have managed
I have developed a java client server app based on socket programming. I am
I'm learning about socket programming in Java. I've seen client/server app examples with some
I'm trying to do some server/socket programming. The server code is written in plain
I've just begun socket programming, and I'm working on an Echo server in Java.
I am basically practicing with Java socket programming by building client and server (not
I'm new to socket programming and programming a Java UDP simple client-server application. I'm
I have this code for Server in socket programming application, and I have this

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.