473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Object Transfer Over Network ( Socket )

Hi All,

I need some advanced samples or references for passing custom objects over
the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder
Nov 21 '05 #1
8 3908
FTP xml?

"rawCoder" <ra******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I need some advanced samples or references for passing custom objects over
the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder

Nov 21 '05 #2
rawCoder,

Basically, you have to use serialization. You will want to serialize
your object to a MemoryStream (or some other stream, but MemoryStream will
return a byte array to you, which will help you later). Once you have the
stream, get the bytes from it (with a MemoryStream you would call the
ToArray method). From there, just pass the bytes to the Send method on the
socket, and you should be fine.

You just have to read the bytes into a MemoryStream (or some other
stream on the other end) and then pass that stream to a formatter for
deserialization.

The things you have to look out for are the length of the message.
Since not all objects serialized into a fixed-length format, you need to
send a prefix over the socket indicating how long the byte stream for the
object will be. Then, on the other side, you will know how many bytes you
need to read to get the contents of the object.

Also, both sides have to have a reference to the assembly containing the
type.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"rawCoder" <ra******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I need some advanced samples or references for passing custom objects over
the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder

Nov 21 '05 #3
rawCoder,
In addition to the other comments, the following article demonstrates how to
use a BinaryReader & BinaryWriter do your own "serialization" to a
NetworkStream.

http://msdn.microsoft.com/library/de...rp09182003.asp

The example is in C#, however it should be easily converted to VB.NET, post
if you need help.

Hope this helps
Jay

"rawCoder" <ra******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I need some advanced samples or references for passing custom objects over
the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder

Nov 21 '05 #4
rawCoder,

I do not know if he sees this thread himself it has alreaydy a lot of
answers. Personally I find this sample from Tom very nice.

\\\by Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
///
\\\
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
///

I hope this helps a little bit?

Cor
"rawCoder" <ra******@hotmail.com>
Hi All,

I need some advanced samples or references for passing custom objects over
the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder

Nov 21 '05 #5
Thank You All for your suggestions.

This information is quite enough for me to get started.
I do not know if he sees this thread himself it has alreaydy a lot of
answers. Cor , did you mean Me here ? :-) If yes then yes I do see my threads ,
infact have them "Watched" in my OE. I actually dont post unless I feel it
very necessary.

Thank You
rawCoder


"Cor Ligthert" <no************@planet.nl> wrote in message
news:us**************@TK2MSFTNGP11.phx.gbl... rawCoder,
\\\by Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
///
\\\
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
///

I hope this helps a little bit?

Cor
"rawCoder" <ra******@hotmail.com>
Hi All,

I need some advanced samples or references for passing custom objects over the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder


Nov 21 '05 #6
> Cor , did you mean Me here ? :-) If yes then yes I do see my threads ,
infact have them "Watched" in my OE. I actually dont post unless I feel it
very necessary.


No I mean Tom Shelton, the sample I sent is from Tom.
You are not with those were I have slight doubts about that.

:-)

Cor
Nov 21 '05 #7
'Serializing variable length string across app domains'

Hi All,

Well I looked into the serialization stuff and seems that the default
serialization of .NEt isnt good enuf for me due to space problem.

the one that suits me most is with the help of Marshal.StructureToPtr
Its concise and good but there is one problem.

In case of unknow length strings , this will not work when the serialization
and de-serialization is done across app domains - as in case of socket apps.
see the structure at the bottom

If there is no direct solution, then I will have to do ALL the serialization
by myself without help from .NET :'-(
Then I will actually not be sending the original objects over network,
rather will be getting the fields out and putting in a generic message with
message header to identify type of message and length and will be then
sending it. Any help in that case will also be appreciated

btw every serialization works very fine in same app domains , but in case of
diff. app domains - things fall apart.

Any suggestions

Thank you in advance
rawCoder

Public Structure STData

Dim a As Integer

'<MarshalAs(UnmanagedType.BStr)> _

Dim b As String

End Structure

"rawCoder" <ra******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I need some advanced samples or references for passing custom objects over
the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder

Nov 21 '05 #8

"rawCoder" <ra******@hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP12.phx.gbl...
'Serializing variable length string across app domains'

Hi All,

Well I looked into the serialization stuff and seems that the default
serialization of .NEt isnt good enuf for me due to space problem.

the one that suits me most is with the help of Marshal.StructureToPtr
Its concise and good but there is one problem.

In case of unknow length strings , this will not work when the serialization and de-serialization is done across app domains - as in case of socket apps. see the structure at the bottom

If there is no direct solution, then I will have to do ALL the serialization by myself without help from .NET :'-(
Then I will actually not be sending the original objects over network,
rather will be getting the fields out and putting in a generic message with message header to identify type of message and length and will be then
sending it. Any help in that case will also be appreciated

In reality, it is impossible to send objects anywhere. They only exist in
memory. As far as applications are concerned, they only exist in the
virutal address space of the process in which they were created. Any idea of
object transfer is going to consist of creating a new object that is the
same type as your source object at your destination location and setting its
state to that of your source object.

I am actually in the same boat as you are. I need a PocketPC to talk to a
windows service written in C#. Even if I use the .Net Compact Frame work on
the PocketPC there is no remoting or serialization available. There is also
no DCOM for PocketPC.

Some of the things I am thinking about are:

1. Is it too much work to setup a generic way to remote object over tcp/ip
(probably)
2. Is it too much work to remote a specific type of object over tcp/ip
(probably not)
a. Create a proxy object
b. Create a stub object
c. Create a specific protocol that will allow me to mirror object state
and perform remote method invocation.
3. Am I better off creating an application specific protocol to expose a set
of services over tcp/ip (perhaps).
btw every serialization works very fine in same app domains , but in case of diff. app domains - things fall apart.

Any suggestions

Thank you in advance
rawCoder

Public Structure STData

Dim a As Integer

'<MarshalAs(UnmanagedType.BStr)> _

Dim b As String

End Structure

"rawCoder" <ra******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I need some advanced samples or references for passing custom objects over the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary serialization.

Thank You
rawCoder


Nov 21 '05 #9

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

Similar topics

6
by: John Walton | last post by:
Hello, everyone. I just began school, and they already assigned us science fair. Since I'm in 8th grade, I get to do demonstrations for our projects. I'm probably going to demonstrate Python's...
1
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote...
8
by: rawCoder | last post by:
Hi All, I need some advanced samples or references for passing custom objects over the network using sockets. Without using Remoting what are other options in .NET Framework for this binary...
2
by: Satish | last post by:
Hello...plz provide sample code on heo top transfer multiple files over a Local network VIA TCP/IP in .net
38
by: Tom | last post by:
I need my data generating C program on computer #1 to export small amounts of data (one - 40 byte data structure) periodically (once per minute) to a C program on computer #2. I am considering...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
2
yashg
by: yashg | last post by:
I am building a data backup application in C# using Sockets. It has a server component and a client component. The client is going to upload files to the server through TCP sockets. I've got all...
7
by: JamesHoward | last post by:
Does anyone know any method to have one program, acting as a server transfer a socket connection to another program? I looked into transferring the connection via xml rpc to no avail. It seems to...
1
by: Saurabh | last post by:
Dear All, Can anyone tell me, how to write such a program that can transfer files (either binary or text) behind NAT devices( such as for computers behind firewalls and routers and other NAT...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.