472,146 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

WriteLine and Linebreak

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
Nov 16 '05 #1
4 2561
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" <_F*******@gmx.net> wrote in message
news:O%****************@TK2MSFTNGP11.phx.gbl...
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

Nov 16 '05 #2
can you post some example code, please?
I'm from germany and not sure if had understand it right :)

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:O9*************@TK2MSFTNGP10.phx.gbl...
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" <_F*******@gmx.net> wrote in message
news:O%****************@TK2MSFTNGP11.phx.gbl...
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


Nov 16 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"Dirk Reske" <_F*******@gmx.net> wrote in message
news:uK*************@TK2MSFTNGP12.phx.gbl...
can you post some example code, please?
I'm from germany and not sure if had understand it right :)

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:O9*************@TK2MSFTNGP10.phx.gbl...
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" <_F*******@gmx.net> wrote in message
news:O%****************@TK2MSFTNGP11.phx.gbl...
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



Nov 16 '05 #4
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.

"Dirk Reske" <_F*******@gmx.net> wrote in message
news:O#**************@TK2MSFTNGP11.phx.gbl...
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

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by nAmYzArC | last post: by
2 posts views Thread by Unemployed VC++ guy | last post: by
reply views Thread by Howard Kaikow | last post: by
5 posts views Thread by portroe | last post: by
2 posts views Thread by Georg Weiler | last post: by
2 posts views Thread by djc | last post: by
3 posts views Thread by Michael Hamm | last post: by
3 posts views Thread by Per W. | last post: by
reply views Thread by leo001 | last post: by

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.