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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:09:00+00:00 2026-06-02T08:09:00+00:00

So i am trying to create something like a syncronized paint program by using

  • 0

So i am trying to create something like a syncronized paint program by using sockets.I have a server side..and a client side and i am trying to send the inkCollection from the server to the client.This works for simple text, but i cant seem to send the inkCollection.Or it would be even cooler if you could help me send the last stroke so that the data transfers faster.Here is some code of what i’ve been trying:

sending strokes:

        byte[] data;
        using (MemoryStream ms = new MemoryStream())
        {
            inkcanvas.Strokes.Save(ms);
            data = ms.ToArray();
        }

        svr.SendToAll("u getting some strokes");
        svr.SendStrokes(data);

svr.SendStrokes(byte[] data):

 public void SendStrokes(byte[] data)
    {
        for (int i = 0; i < no; i++)
        {
            byte[] dt = data;
            accepted[i].Send(dt);
        }

            MessageBox.Show("dONE");
    }

and this is on the clientside:

 byte[] buffer=new byte[1024];
                MessageBox.Show("receiving strokes");
                int rec = conn.Receive(buffer, 0, buffer.Length, 0);
                if (rec <= 0)
                    throw new SocketException();
                MessageBox.Show("strokes received");
                //Array.Resize(ref buffer, rec);
                using (MemoryStream ms = new MemoryStream(buffer))
                {
                    inkcanvas.Strokes = new System.Windows.Ink.StrokeCollection(ms);
                    ms.Close();
                }
                MessageBox.Show("strokes added");

these exact same methods work perfectly for string, but when i try to do it with the strokeCollection, it fails.Nothing shows up on the client and i get the following SocketException ont the serverside: An existing connection was forcibly closed by the remote host.

But if you guys got a better way on how to do this it would be great…is it something i am missing? i mean..if it works for text transformed into a byte array…why wouldint it work for this strokecollection?

Thanks!

EDIT: You think you could help me out with some sample code? i cant really seem to implement it;

  • 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-02T08:09:01+00:00Added an answer on June 2, 2026 at 8:09 am

    You forgot to either design or implement a protocol! You can’t just send a bunch of bytes over TCP and assume the receiver will be able to make sense out of it.

    You have an application message that consists of a bunch of strokes which you are trying to send over TCP. But TCP is a byte stream service, not an application message service. So you need some kind of application message protocol to package the message for transport and unpackage it on receipt. But you have not written any such code. So you’re basically expecting it to work by magic.

    Define a protocol. For example, it might say:

    Canvas strokes shall be sent by a ‘1’ byte indicating canvas strokes, followed by 4 bytes indicating the number of bytes in the strokes object in network byte order, followed by the stroke data. The receiver will read the first byte and identify that it’s a canvas strokes object. Then the receiver will read the next four bytes to determine the length. The receiver shall accumulate that number of bytes (using multiple reads if necessary) and then process the reconstructed canvas strokes object.

    Do not skip the step of creating a written protocol definition.

    Then, when you have problems, follow this handy troubleshooting guide:

    1. Does the sender follow the specification? If not, stop, the sender is broken.

    2. Does the receiver follow the specification? If not, stop, the receiver is broken.

    3. Stop, the specification is broken.

    If you want simple, you can convert the data into base64 and encode each message as a line of text. That will allow you to use a ReadLine function to grab exactly one message. Then you can just use a message format like an “S” (for “strokes”) followed by the data in base64 format. Use a WriteLine function to send the text message followed by a newline.

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

Sidebar

Related Questions

I am trying to create something like this as i have done it in
I am trying to create something like this: But I have problems beacuse it
I am trying to create something like a Network Manager using NSUrlConnections. For that,
Im trying to create something that looks like this using php gd library: I've
I have been trying to create something like: http://jquerystyle.com/index.php - when you go over
I am trying to create something like this: This example creates view using a
I'm trying to create something like a MDI tabbed Interface so I have a
I'm trying to create XML Schema using lxml. For the begining something like this:
I am trying to create something in Perl that is basically like the Unix
I'm trying to create a user control that allows users to make something like

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.