Skip to content

Sending an instance of a form and all it's info from Computer A to Computer B

Robin_Cox

Asked Feb 9, 2006, 11:29 AM EST3 answers
Share
LinkedInX

I have to identical applications written by me operating on two different machines.  I want to send either a complete instance of a form across a TCP/IP network to a peer machine, or at least the class other information necessary to recreate the form on the remote computer.  I believe it can be achieved with a TCP/IP client and employing the use of unsafe memory pointers to access the memory space of the form.  Surely there are simpler ways to achieve this???

Any ideas greatfully accepted.

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    How does the unmanaged pointers help when transferring data over network...? Other machine can never access directly to other machine.

    Well, you could make a custom carrier class, which can carry all relevant information you need to duplicate the form behaviour at the other machine. Serializing the whole System.Windows.Form would be quite useless.

    The carrier object would be serialized in local machine to xml or binary, and transferred to the remote machine, and deserialized there, and new form is initialized there according to the information of the carrier object.

    This is the way I would do it:

    1) create form
    2) create and initialize carrier object
    3) serialize carrier to either xml or binary

    4) transfer carrier to other machine over the protocol you choose

    5) deserialize carrier data to carrier object
    6) create and initialize your new form using carrier's data
    7) show your form

    Transferring data to xml is simple using XmlSerializer-object. See MSDN for an example. Well, you could try to serialize the whole Form object, but it consumes lots of network resources, since it has many, many fields. But if the transfer is happening quite seldom, go ahead.

    0
  • 0
    I know that a form can't be serialized. It's this right?
    0
  • Anwar Buchoo
    0
    The XmlSerializer can serialise any object as far as I know, and as such, a form is an object.

    Items That Can Be Serialized:

    The following items can be serialized using the XmlSerializer class.

    • Public read/write properties and fields of public classes.
    • Classes that implement ICollection or IEnumerable. (Note that only collections are serialized, not public properties.)
    • XmlElement objects.
    • XmlNode objects.
    • DataSet objects.
      (source MSDN online help)

    0