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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:46:08+00:00 2026-06-02T05:46:08+00:00

Ok this is the final hurdle I’m struggling with. Im trying to allow a

  • 0

Ok this is the final hurdle I’m struggling with.

Im trying to allow a client to communicate with a single other client when they prefix the target clients name to their message.

For example if Ian wanted to communicate with bill he would type:

bill hi mate

Now, currently when a new client connects to the server their name is stored in an array list. As this uses data packets and byte buffers it means that when I store a name, it also stores that names length. By default on the server the data packets buffer size is 512, therefore each names length is 512.

This hasn’t been an issue until now. I have done the following to get who the client wants to communicate with:

else 
{
    System.out.println( "Client said: "+response+"\nPacket Size: "+packet.getLength()+"\nString Length: "+response.length() );
    String [] usrInput = response.split( " " );
    System.out.println( "Length of split string: "+usrInput.length );
}

It splits their input into an array and looks at the first position of the array for the name. So, from above, we would have bill in the first position.

Here is where I go wrong; I tried using:

  1. contains()
  2. equals()
  3. matches()

and so on but all fail; I’m guessing because of the length of the name stored. So how can I reduce the size of the name stored to just, for example, bill – 4?

Cheers

  • 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-02T05:46:11+00:00Added an answer on June 2, 2026 at 5:46 am

    You are constructing the string fom the packet incorrectly. The DatagramPacket contains its own actual length. You should be using that, rather than the length of the entire byte array.

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

Sidebar

Related Questions

I am trying to do something like this final Map<String, ? extends Object> params
i put a drawable in a EditText with this code: final Drawable x =
This is the final output Output http://img2.pict.com/cc/dc/64/3257730/0/20100330041140.png My HTML <li id='$id'>TEXT <ul class='indent'> <li
this is my final query select Codigo, Indicador, case when Indicador like '%Porcentaje%' then
Whi with this code public final String[] array_titoli_serie_prima = new String[]{ getResources().getString(R.string.titolo_p1), getResources().getString(R.string.titolo_p2), getResources().getString(R.string.titolo_p3),
I created a table without a primary key Like this: private static final String
Java Naming rules suggests which one to be used. This public static final class
Consider this case: public Class1 { public static final String ONE = ABC; public
considering this example: public static void main(final String[] args) { final List<String> myList =
This code is invalid: interface Foo { public void foo(final String string); } public

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.