473,788 Members | 2,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sockets

How do I send an object from one computer to another?

--
I am a 14 year old C# developer, I am completely self taught, so please
don't get mad if I ask a stupid question. Thanks.
Nov 16 '05 #1
7 2319
Welcome to the world of distributed programming - theres a whole new world of things you have to think abouit. The first one here is what do you want to happen when you pass this object when the recipient calls it? Do you want the call to come back to the sender or do you want the call to stay on teh remote machine?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

How do I send an object from one computer to another?

--
I am a 14 year old C# developer, I am completely self taught, so please
don't get mad if I ask a stupid question. Thanks.

Nov 16 '05 #2
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.G etBytes(), 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" <nu****@comcast .net> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
How do I send an object from one computer to another?

--
I am a 14 year old C# developer, I am completely self taught, so please
don't get mad if I ask a stupid question. Thanks.


Nov 16 '05 #3
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 [MVP]" wrote:
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.G etBytes(), 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" <nu****@comcast .net> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
How do I send an object from one computer to another?

--
I am a 14 year old C# developer, I am completely self taught, so please
don't get mad if I ask a stupid question. Thanks.


Nov 16 '05 #4
Is this a peer to peer application then?

if it is client to client then some issues of scaleability don't come into play.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Nov 16 '05 #5
I just told you one way. You can use Remoting or sockets. As you talked
about sockets, I told you how to use XmlSerializer to do it. I assume you
know how to send bytes, so all you need to convert your class instance into
bytes using xmlserializer and an Encoding to convert the string to bytes.
Check the XmlSerializer doco. It is really helpful. If you have specific
questions, please reply.

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Bill English" <nu****@comcast .net> wrote in message
news:0E******** *************** ***********@mic rosoft.com...
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 [MVP]" wrote:
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.G etBytes(), 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" <nu****@comcast .net> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
How do I send an object from one computer to another?

--
I am a 14 year old C# developer, I am completely self taught, so please don't get mad if I ask a stupid question. Thanks.



Nov 16 '05 #6

"Bill English" <nu****@comcast .net> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
How do I send an object from one computer to another?

--
I am a 14 year old C# developer, I am completely self taught, so please
don't get mad if I ask a stupid question. Thanks.

Nov 16 '05 #7
..Net remoting is a good place to start. I would start your research there.
If you go this way, you may also want to try copying your object from one
application to another first. Many of the same skills are required and you
wont have to hassle with two machines at first.

More information:

I always find it helpful to think of networking in terms of the layering of
increasing complex protocols. You need to make sure that your communication
is established properly at the lower levels before moving to the higher
levels. The first thing you need is a physical connection between the two
machines (like a network cable). Then you need a way to pass generic
information between machines like tcp/ip. Then you will want to layer more
complex protocols on top of this to accomplish your task. The complexity of
each layer has resource and performance costs that need to be weighed
against available resources and performance requirements. Lower level
protocols will most likely be faster, less resource intensive, and more
versatile, but require more effort to implement and are harder to read when
revisited.

That being said it is important to understand your problem space. You want
to send an object from one computer to another. However, you are really not
sending an object from one computer to another. You are making a copy of an
object from one computer on another computer. If you have the class
definition on both machines then you can create an object instance on both
machines. Then you need to transmit the state of the source object from one
machine to the other and update the state of the destination object with
that state information. You will need to take your source object and
serialize its state into a data stream. You are basically packaging it in a
compact form for transmission across the wire. When it goes across the wire
you will then want to reassemble it into a usable form, i.e. your object.
You would have to perform a similar operation even communicating from one
program to another. Obviously you wouldn't be sending object state across
machine boundaries, but you would be sending it across process boundaries.

There are technologies that perform this type of action in one form or
another depending on the needs of the application and the environment in
which your objects will communicate. .Net remoting is one of those
technologies. It provides you the ability to work on a copy of an object or
to appear to act on one object from different machines by updating the
original when the copy is acted on. There are a lot of problems inherent in
working on remote objects as if they were local. It is appropriate in
certain situations especially if you are in control of all aspects of the
system in which the objects are contained and there are not a ton of users
accessing the object. However, if the system is more spread out and the
environment not so controlled you may want to work with copies or consider
other alternatives. An evolving school of thought is Service Orientation or
SOA (Service Oriented Applications)

"Bill English" <nu****@comcast .net> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
How do I send an object from one computer to another?

--
I am a 14 year old C# developer, I am completely self taught, so please
don't get mad if I ask a stupid question. Thanks.

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3896
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add support for sockets to the system. Thread needs to unblock when: - there is socket ready to be read, or
1
3797
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for pending connections every 500ms. I also have a vb6 application that uses the WinSock control at the other end of the communication tunel. I have to work with vb6 here because it uses less memory than .NET.
0
1831
by: mrpolitics | last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd) and everything was fine untill yesterday when the server crashed. So I did a cold restart and staretd the server back up now it's throwing this stream of errors right away. Does anyone have any idea what they mean. I havn't changed the source at all since it was working (which was for four days). It errors here saying An unhandled exception of type...
3
10402
by: Logan McKinley | last post by:
I have a C# program that uses blocking sockets and want to allow the user to stop the server. The problem I am having is the socket blocks on -------------------------------------------------------------- listener = new System.Net.Sockets.TcpListener(6254); listener.Start(); //skt is a socket skt =listener.AcceptSocket(); <--- this line blocks -------------------------------------------------------------- I attempt to stop the thread...
1
20351
by: Adam Clauss | last post by:
I am (attempting) to move an existing socket application to use raw sockets. Right now, my application is essentially a port forwarder. Upon receiving a connection, it will open a connection to an "internal" server and simply relay all information back and forth (when the client sends something, my app sends that to the server, when server sends something, my app sends that to the client). While what I have right DOES work, the...
4
6321
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
4363
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly found out that .net uses system.net.sockets.socket or .tcpclient/.tcpserver. and these confuse me... :o| and help would be really great! links, code, wrappers, tips, whateveryougot... one of my main problems, i guess, is: why don't sockets...
3
11594
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.ReceiveFrom(Byte buffer, Int32 offset, Int32 s
7
6723
by: Adam01 | last post by:
Im using cygwin to test the code of a server I am writing. I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h. And this is the output.. ../../../sockets.cpp: In constructor `network_class::network_class()': ../../../sockets.cpp:64: error: aggregate `addrinfo hints' has incomplete type a nd cannot be defined ../../../sockets.cpp:69: error: `getaddrinfo' undeclared (first use this functio n)
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.