Sign in to follow this  
hawflakes

[.net] Sending, Reading XML protocol accross sockets as Strings

Recommended Posts

I'm fairly new to XML and have managed to set up a protocol for messages in a connect 4 game. Now the difficulty I'm having is figuring out how to write the XML to a string instead of a file so that I can send outgoing messages as Strings and read it in a similar way, from a string so that I can see what type it is. I'm sure what I'm looking for isn't that difficult, I'm just searching with no avail for how to do this without needing a text file or IO stream

Share this post


Link to post
Share on other sites
Not sure why you want to change the xml to strings and then send it accoss the sockets. The easier way is just to use the XML serialize and then stream that to your sockets. The XML classes support serialation so it should be no problem.

theTroll

Share this post


Link to post
Share on other sites
To "serialize" the data is to persist it in a form that it can be recreated from, whole. (This process is often called hydration/dehydration.) When you write your object to a file, you're serializing it. I mention this because knowing the terms to look for can be more helpful in the long run than a bunch of gobbledly gook that someone spits out at you.

If you're able to persist the data to a file you should have no problem sending it across the network. Both are forms of a stream - one is a FileStream, the other is a NetworkStream.

To use the automatic serialization capabilities of the Framework, apply the [Serializable] attribute to the class or object you wish to transport. The Serializable attribute serializes the public and private fields of an object; you can control the serialization of a particular member (i.e. if it is read only or lookup data) by applying the [NonSerializedAttribute]. You can control the serialization process complete by implementing the [ISerializable] interface.

Share this post


Link to post
Share on other sites
I'd never heard the term hydration used in that context before, well I guess you learn somehting everyday.

According to this post your partially correct.

http://www.techwr-l.com/techwhirl/archives/0508/techwhirl-0508-00253.html

He thinks hydration is serialization to xml. Good to know! Ratings++

Cheers
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by chollida1
I'd never heard the term hydration used in that context before, well I guess you learn somehting everyday.

According to this post your partially correct.

http://www.techwr-l.com/techwhirl/archives/0508/techwhirl-0508-00253.html

He thinks hydration is serialization to xml. Good to know! Ratings++

Cheers
Chris


I know it started with Biztalk Server (I believe it was the term used to indicate writing intermediate objects to disk; Biztalk is XML based, so that fits into the above statements). My actual hands on experience with Biztalk is null though. Microsoft uses it on a few articles they've written. (One here, an ASP.NET example here.) They seem to be pushing it as a new term for serialization to XML; I had not picked up that minor detail prior, thank you. (Everyone wants to serialize to XML, examples of serialization to any format other than XML are few and far between.)

Personally, I find serialization/deserialization fits the bill just fine. Why introduce more buzzwords? May as well ask, "Why is the sky blue?" (Please, don't let someone answer that. :))

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this