G
Guest
How do I send an object from one computer to another?
William Stacey said:Well if you just want the public fields of an object (say a class is an
abstract db record) then you can just use XmlSerializer to serialize the
class to an xml string. Now that you have the string you can easily get the
bytes using Encoding.UTF8.GetBytes(), etc. Now you have the bytes, you can
send in a UDP datagram or send via TCP stream. If using TCP, you probably
want to append a len ushort to the byte[]. Then the receive side will read
the first two bytes, convert to a ushort and then read that many bytes to
know it got all the bytes. Then close or wait for more data. The receiver
will also convert the bytes back to a string, and deserialize string to an
object. Both sides need to know what "object" looks like, so you can
include the same class code at both sides. One way to do that is create a
shared dll. This dll may be nothing more then all the "shared" objects or
data tranfer objects (DTOs). In a sense, I guess the class defines the
shared schema or contract of what both sides expect to send and receive in
terms of object data. Like Richard said, this is a big topic with various
ways to go and can get complex. Today, you have many techs to choose from
to do this. You have WSE, web services, Remoting, and native sockets using
your own "wire" protocol (and others). Using xml over sockets is probably a
good way to start as you get a handle on it from ground up, and get a feel
for why and how the others work the way they do. The other techs are
variations on their own xml over socket technologies. Remoting does not use
xml, but you could think of it as its own propriatary binary markup
language. All of them output byte[] of some kind that must be sent over a
udp or tcp socket. Indigo will be MSs next version of xml over sockets that
will combine ~all the others into one api set.
Bill English said:The class I want to send is already on both computers, however, I just want
to know how to Asyncronously send an instance of the class back and forth
from computer to computer.
William Stacey said:Well if you just want the public fields of an object (say a class is an
abstract db record) then you can just use XmlSerializer to serialize the
class to an xml string. Now that you have the string you can easily get the
bytes using Encoding.UTF8.GetBytes(), etc. Now you have the bytes, you can
send in a UDP datagram or send via TCP stream. If using TCP, you probably
want to append a len ushort to the byte[]. Then the receive side will read
the first two bytes, convert to a ushort and then read that many bytes to
know it got all the bytes. Then close or wait for more data. The receiver
will also convert the bytes back to a string, and deserialize string to an
object. Both sides need to know what "object" looks like, so you can
include the same class code at both sides. One way to do that is create a
shared dll. This dll may be nothing more then all the "shared" objects or
data tranfer objects (DTOs). In a sense, I guess the class defines the
shared schema or contract of what both sides expect to send and receive in
terms of object data. Like Richard said, this is a big topic with various
ways to go and can get complex. Today, you have many techs to choose from
to do this. You have WSE, web services, Remoting, and native sockets using
your own "wire" protocol (and others). Using xml over sockets is probably a
good way to start as you get a handle on it from ground up, and get a feel
for why and how the others work the way they do. The other techs are
variations on their own xml over socket technologies. Remoting does not use
xml, but you could think of it as its own propriatary binary markup
language. All of them output byte[] of some kind that must be sent over a
udp or tcp socket. Indigo will be MSs next version of xml over sockets that
will combine ~all the others into one api set.
--
William Stacey, MVP
http://mvp.support.microsoft.com
Bill English said:How do I send an object from one computer to another?
Bill English said:How do I send an object from one computer to another?