WriteLine and Linebreak

  • Thread starter Thread starter Dirk Reske
  • Start date Start date
D

Dirk Reske

Hey,

I have following struct:

struct Packet
{
string Command;
byte[] data;
}

I want to send this trough an open Network connection.
I serialize it first and remove all linebreaks in the XML data.
When I send it using WriteLine(strXML), what happens with linebreaks in the
bytearray?
Does it only send the content til the linebreak?

thx
 
Dirk,

You shouldn't be modifying the XML data. Rather, you should tranform it
to contain the linebreaks (using something like base64 or something).

Or better yet, why not serialize to a binary format and then encode
using base64? You don't have to worry about linebreaks then.

Why are you removing the linebreaks at all? Is the message you are
sending dependent on linebreaks? If you have dynamic content in your
messages, then you need to have some method of accounting for the fact that
the dynamic content could have linebreaks itself. Modifying the content is
a bad idea, because then you can end up with errors due to the
transformation (plus the fact that you are modifying it is a generally bad
idea). If anything, transform it to a format that doesn't have line breaks,
and send that.
 
can you post some example code, please?
I'm from germany and not sure if had understand it right :)

Nicholas Paldino said:
Dirk,

You shouldn't be modifying the XML data. Rather, you should tranform
it to contain the linebreaks (using something like base64 or something).

Or better yet, why not serialize to a binary format and then encode
using base64? You don't have to worry about linebreaks then.

Why are you removing the linebreaks at all? Is the message you are
sending dependent on linebreaks? If you have dynamic content in your
messages, then you need to have some method of accounting for the fact
that the dynamic content could have linebreaks itself. Modifying the
content is a bad idea, because then you can end up with errors due to the
transformation (plus the fact that you are modifying it is a generally bad
idea). If anything, transform it to a format that doesn't have line
breaks, and send that.



Dirk Reske said:
Hey,

I have following struct:

struct Packet
{
string Command;
byte[] data;
}

I want to send this trough an open Network connection.
I serialize it first and remove all linebreaks in the XML data.
When I send it using WriteLine(strXML), what happens with linebreaks in
the bytearray?
Does it only send the content til the linebreak?

thx
 
Dirk,

Instead of transforming the XML, why not call the static ToBase64String
method on the Convert class, that way, you can get a section of text to send
with no line breaks.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dirk Reske said:
can you post some example code, please?
I'm from germany and not sure if had understand it right :)

Nicholas Paldino said:
Dirk,

You shouldn't be modifying the XML data. Rather, you should tranform
it to contain the linebreaks (using something like base64 or something).

Or better yet, why not serialize to a binary format and then encode
using base64? You don't have to worry about linebreaks then.

Why are you removing the linebreaks at all? Is the message you are
sending dependent on linebreaks? If you have dynamic content in your
messages, then you need to have some method of accounting for the fact
that the dynamic content could have linebreaks itself. Modifying the
content is a bad idea, because then you can end up with errors due to the
transformation (plus the fact that you are modifying it is a generally
bad idea). If anything, transform it to a format that doesn't have line
breaks, and send that.



Dirk Reske said:
Hey,

I have following struct:

struct Packet
{
string Command;
byte[] data;
}

I want to send this trough an open Network connection.
I serialize it first and remove all linebreaks in the XML data.
When I send it using WriteLine(strXML), what happens with linebreaks in
the bytearray?
Does it only send the content til the linebreak?

thx
 
Check out Synapse for C#
You can simply serialize into a memorystream and use the sendstream method,
then use recvstream on the other side.
You can get the Synapse TCP assembly at
http://groups.yahoo.com/group/synalist/ in the files area.

You can also do readstring and sendstring without the overhead of the C#
networkstream or the streamwriter/reader classes.
 
Back
Top