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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:47:21+00:00 2026-05-22T15:47:21+00:00

I’m programming a game which sends the position of the player to the server

  • 0

I’m programming a game which sends the position of the player to the server whenever the player moves, using XML like this:

<?xml version="1.0" encoding="utf-8" ?> <request type="movement"> <character map="1" coords="10,20"/> </request>

The thing is, since the information is sent very fast, it usually sends two or three times the XML in the same packet and then the server cannot parse it correctly.

In the client side, using C# .net I create a new Task in order to send the info so that it continues to update the game correctly, in the task I simply call Socket.send to send XML as a text string.

Client:

Byte[] bytesToSend = Encoding.ASCII.GetBytes(texto);
socket.Send(bytesToSend, bytesToSend.length, 0);

Java Server:

public String convertStreamToString(InputStream is) throws Exception {
        BufferedInputStream reader = new BufferedInputStream(is);
        byte[] ent = null;
        int recivido;
        // String line = reader.readLine();
        do {
            ent = new byte[reader.available()];


            recivido = reader.read(ent);
        } while (recivido == 0);

        return new String(ent);
    }
  • 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-22T15:47:22+00:00Added an answer on May 22, 2026 at 3:47 pm

    TCP works like that since it’s stream based and not message based.

    Read my answer here: Application stops when receiving info through socket

    Client side:

    var buffer = Encoding.UTF8.GetBytes(yourXml);
    var header = BitConverter.GetBytes(buffer.Length);
    socket.Send(header);
    socket.Send(buffer);
    

    Server side:

    var header = new byte[4];
    var received = socket.Receive(header, 0, 4);
    var xmlBuffer = new byte[BitConverter.ToInt32(header)];
    socket.Receive(xmlBuffer, 0, xmlBuffer.Length);
    

    Note that you have to keep Receiving until you really got 4 bytes and then the number of bytes received in the length header. (I did not do that in my example)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker

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.