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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:50:06+00:00 2026-05-14T16:50:06+00:00

There are 4 months since I stopped developing my Silverlight Multiplayer Chess game. alt

  • 0

There are 4 months since I stopped developing my Silverlight Multiplayer Chess game.

alt text http://img408.imageshack.us/img408/8355/chess.gif

The problem was a bug wich I couldn’t reproduce. I am very sad because this was a test and many Silverlight multiplayer games will come if this will be a success. There are no examples on the internet about how to do stuff like that, not to mention that only few people use Sockets in their programming life.

Since I got some free time this week I managed to discover the problem and I am now able to reproduce the bug.

It seems that if I send 10 messages from client, one after another, with no delay between them, just like in the below example

// when I press Enter, the client will 10 messages with no delay between them
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter && textBox.Text.Length > 0)
    {
        for (int i = 0; i < 10; i++)
        {
            MessageBuilder mb = new MessageBuilder();
            mb.Writer.Write((byte)GameCommands.NewChatMessageInTable);
            mb.Writer.Write(string.Format("{0}{2}: {1}", ClientVars.PlayerNickname, textBox.Text, i));
            SendChatMessageEvent(mb.GetMessage());

            //System.Threading.Thread.Sleep(100);
        }

        textBox.Text = string.Empty;
    }
}

    // the method used by client to send a message to server
    public void SendData(Message message)
    {
        if (socket.Connected)
        {
            SocketAsyncEventArgs myMsg = new SocketAsyncEventArgs();
            myMsg.RemoteEndPoint = socket.RemoteEndPoint;
            byte[] buffer = message.Buffer;
            myMsg.SetBuffer(buffer, 0, buffer.Length);

            socket.SendAsync(myMsg);
        }
        else
        {
            string err = "Server does not respond. You are disconnected.";
            socket.Close();
            uiContext.Post(this.uiClient.ProcessOnErrorData, err);
        }
    }

    // the method used by server to receive data from client
    private void OnDataReceived(IAsyncResult async)
    {
        ClientSocketPacket client = async.AsyncState as ClientSocketPacket;
        int count = 0;
        try
        {
            if (client.Socket.Connected)
                count = client.Socket.EndReceive(async);
            // THE PROBLEM IS HERE
            // IF SERVER WAS RECEIVE ALL MESSAGES SEPARATELY, ONE BY ONE, THE COUNT
            // WAS ALWAYS 15, BUT BECAUSE THE SERVER RECEIVE 3 MESSAGES IN 1, THE COUNT
            // IS SOMETIME 45
        }
        catch 
        {
            HandleException(client);
        }

        client.MessageStream.Write(client.Buffer, 0, count);

        Message message;

        while (client.MessageStream.Read(out message))
        {
            message.Tag = client;
            ThreadPool.QueueUserWorkItem(new WaitCallback(this.processingThreadEvent.ServerGotData), message);
            totalReceivedBytes += message.Buffer.Length;
        }

        try
        {
            if (client.Socket.Connected)
                client.Socket.BeginReceive(client.Buffer, 0, client.Buffer.Length, 0, new AsyncCallback(OnDataReceived), client);
        }
        catch 
        {
            HandleException(client);
        }
    }

there are sent only 3 big messages, and every big message contain 3 or 4 small messages. This is not the behavior I want.

If I put a 100 milliseconds delay between message delivery, everything is work fine, but in a real world scenario users can send messages to server even at 1 millisecond between them.

  1. Are there any settings to be done in order to make the client send only one message at a time, or
  2. Even if I receive 3 messages in 1, are they full messages all the time (I dont’t want to receive 2.5 messages in one big message) ? because if they are, I can read them and treat this new situation
  • 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-14T16:50:06+00:00Added an answer on May 14, 2026 at 4:50 pm

    You missed the main feature of TCP – it’s not a message-based protocol. It sends all data via single “pipe”. When you put 5 cups of water into the pipe, you get a bucket of water on another end, and not five cups. If you are quick enough to take the water out of the bucket, you can get either 5 cups or 10 half-cups or one bucket. The same with TCP. If you need messages, you must put some markers at the beginning and the end of each message, and parse the stream on the receiving end.

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

Sidebar

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.