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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:40:43+00:00 2026-05-25T11:40:43+00:00

guys! I am write a simple program to send a message to a Game

  • 0

guys! I am write a simple program to send a message to a Game server(Counter-Strike), that message is used to query server information, it has a fixed format:

0xff, 0xff, 0xff, 0xff, 0x54, 0x53, 0x6f, 0x75, 
0x72, 0x63, 0x65, 0x20, 0x45, 0x6e, 0x67, 0x69, 
0x6e, 0x65, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79, 
0x00

My java program:

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Test {

    private static DatagramSocket ds;

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            ds = new DatagramSocket(27022);
            byte[] data;
            // TSource Engine Query
            char peer0_0[] = { 
                0xff, 0xff, 0xff, 0xff, 
                0x54, 0x53, 0x6f, 0x75,
                0x72, 0x63, 0x65, 0x20, 
                0x45, 0x6e, 0x67, 0x69, 
                0x6e, 0x65, 0x20, 0x51, 
                0x75, 0x65, 0x72, 0x79, 0x00 
            };
            data = new String(peer0_0).getBytes();

            System.out.println("send: " + new String(data));

            DatagramPacket dp = new DatagramPacket(data, 0, data.length, InetAddress.getByName("219.133.59.20"), 27021);

            ds.send(dp);
            byte[] rec = new byte[1024];
            DatagramPacket dp2 = new DatagramPacket(rec, 1024);
            ds.receive(dp2);

            System.out.println("receive: " + new String(rec));

            ds.close();
        } catch (IOException e) {
            e.printStackTrace();
            if(ds != null) ds.close();
        }
    }

}

but when I run it, I use wireshark to capture the packet, I got this :

enter image description here
the first four bytes are 0x3f not 0xff, so what’s problem? I am running java 6 on windows 7 Chinese edition.

  • 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-25T11:40:43+00:00Added an answer on May 25, 2026 at 11:40 am

    The conversion from char[] to byte[] via String is not guaranteed to be lossless, since it involves charset conversions.

    Try declaring peer0_0[] as a byte array and working with it directly.

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

Sidebar

Related Questions

Guys, I am trying to write a class in C# that can be used
I have been looking at Reflection.Emit recently. I wrote a simple program that generates
i dont exactly know how write down this query, so im asking your guys
Hay Guys, i want to write a simple NNTP client, which can connect to
I have a simple Screen class in C# that has a bunch of events
Could you guys give me an example how to read and write from/to xml
Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to
I have a file with millions of URLs/IPs and have to write a program
The day came when I had to write a BASH script that walks arbitrary
I found this article about simple proxy server implemented in JAVA: http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm The code

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.