By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,657 Members | 862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,657 IT Pros & Developers. It's quick & easy.

Sending XML data via socket

P: n/a
I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?

Thanks
Jul 30 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Markgoldin,

What are the line breaks representing? Are there actual line breaks
that are being injected into the stream somehow, or does it symbolize the
breaks in what you are reading from the server?

What is the code that you are using to call from the stream? Are you
checking the return value to see that all of the bytes that you requested to
read are actually being read, or are you just assuming that the bytes are
being read completely?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Markgoldin" <ma*************@yahoo.comwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
>I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?

Thanks

Jul 30 '08 #2

P: n/a
<Are there actual line breaks
that are being injected into the stream somehow
Yes, I think that is what happens. I am not sending line breaks at these
positions.

<What is the code that you are using to call from the stream?
I have my code posted in "Multiple socket clients" message.
If you can't see it I will post it again.

Thanks alot for help.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:e4**************@TK2MSFTNGP04.phx.gbl...
Markgoldin,

What are the line breaks representing? Are there actual line breaks
that are being injected into the stream somehow, or does it symbolize the
breaks in what you are reading from the server?

What is the code that you are using to call from the stream? Are you
checking the return value to see that all of the bytes that you requested
to read are actually being read, or are you just assuming that the bytes
are being read completely?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Markgoldin" <ma*************@yahoo.comwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
>>I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?

Thanks


Jul 30 '08 #3

P: n/a
On Jul 30, 11:19*am, "Markgoldin" <markgoldin_2...@yahoo.comwrote:
I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
* * * * <serverdata>
* * * * * * * * <coderun>updateFloor</coderun>
* * * * * * * * <area>MD2</area>
* * * * * * * * <zone>BOXING</zone>
* * * * * * * * <status>Running</status>
* * * * * * * * <job>1000139233</job>
* * * * * * * * <sku>02219</sku>
* * * * * * * * <finished>88</finished>
* * * * </serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
* * * * <serverdata>
* * * * * * * * <coderun>updateFloor</coderun>
* * * * * * * * <area>MD2</area>
* * * * * * * * <zone>BOXING</zone>
* * * * * * * * <status>Running</status>
* * * * * * * * <job>1000139233</job>
* * * * * * * * <sku>02219</sku>
* * * * * * * * <finished>88</finished>
* * * * </serverda
ta>
</VFPData>
or like this:
<VFPData>
* * * * <serverdata>
* * * * * * * * <coderun>updateFloor</coderun>
* * * * * * * * <area>MD2</area>
* * * * * * * * <zone>BOXING</zone>
* * * * * * * * <status>Running</status>
* * * * * * * * <job>1000139233</job>
* * * * * * * * <sku>02219</sku>
* * * * * * * * <fini
shed>92</finished>
* * * * </serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?

Thanks
can you post the code you are using to get it from the network stream?
Are you calling WriteLine somewhere?
Jul 30 '08 #4

P: n/a
My code is posted in my message "Multiple socket clients".
Let me know if you can't see it I will post it here.

Thanks for the help.

"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:c7**********************************@x41g2000 hsb.googlegroups.com...
On Jul 30, 11:19 am, "Markgoldin" <markgoldin_2...@yahoo.comwrote:
I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?

Thanks
can you post the code you are using to get it from the network stream?
Are you calling WriteLine somewhere?
Jul 30 '08 #5

P: n/a
Generally, you should post the code in the same thread. The reason for
this is that there can be a LOT of threads in a newsgroup and a lot of
messages.

Looking at the code you posted, how do you know how many total bytes
make up the message? In other words, when a message is sent, when do you
know the XML ends? In a situation like this, you should be sending the
length of the message first to indicate the number of bytes that make up the
message, and then read that number of bytes.

Also, it's not guaranteed that the Stream will return the number of
bytes that you request to read. Because of that, you might have to call it
multiple times. Check out Jon Skeet's site which goes into more detail:

http://www.yoda.arachsys.com/csharp/readbinary.html

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

"Markgoldin" <ma*************@yahoo.comwrote in message
news:OC**************@TK2MSFTNGP06.phx.gbl...
<Are there actual line breaks
>that are being injected into the stream somehow
Yes, I think that is what happens. I am not sending line breaks at these
positions.

<What is the code that you are using to call from the stream?
I have my code posted in "Multiple socket clients" message.
If you can't see it I will post it again.

Thanks alot for help.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e4**************@TK2MSFTNGP04.phx.gbl...
>Markgoldin,

What are the line breaks representing? Are there actual line breaks
that are being injected into the stream somehow, or does it symbolize the
breaks in what you are reading from the server?

What is the code that you are using to call from the stream? Are you
checking the return value to see that all of the bytes that you requested
to read are actually being read, or are you just assuming that the bytes
are being read completely?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Markgoldin" <ma*************@yahoo.comwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
>>>I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?

Thanks



Jul 30 '08 #6

P: n/a
What I am trying to do is to read the whole lot into a buffer.
Can I somehow read untill a special character is met? Something like char
13?
That way I dont have to send a number of bytes to read.

Thanks

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:e1*************@TK2MSFTNGP02.phx.gbl...
Generally, you should post the code in the same thread. The reason for
this is that there can be a LOT of threads in a newsgroup and a lot of
messages.

Looking at the code you posted, how do you know how many total bytes
make up the message? In other words, when a message is sent, when do you
know the XML ends? In a situation like this, you should be sending the
length of the message first to indicate the number of bytes that make up
the message, and then read that number of bytes.

Also, it's not guaranteed that the Stream will return the number of
bytes that you request to read. Because of that, you might have to call
it multiple times. Check out Jon Skeet's site which goes into more
detail:

http://www.yoda.arachsys.com/csharp/readbinary.html

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

"Markgoldin" <ma*************@yahoo.comwrote in message
news:OC**************@TK2MSFTNGP06.phx.gbl...
><Are there actual line breaks
>>that are being injected into the stream somehow
Yes, I think that is what happens. I am not sending line breaks at these
positions.

<What is the code that you are using to call from the stream?
I have my code posted in "Multiple socket clients" message.
If you can't see it I will post it again.

Thanks alot for help.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e4**************@TK2MSFTNGP04.phx.gbl...
>>Markgoldin,

What are the line breaks representing? Are there actual line breaks
that are being injected into the stream somehow, or does it symbolize
the breaks in what you are reading from the server?

What is the code that you are using to call from the stream? Are you
checking the return value to see that all of the bytes that you
requested to read are actually being read, or are you just assuming that
the bytes are being read completely?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Markgoldin" <ma*************@yahoo.comwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all
the time.
What do I need to do to keep XML well formed?

Thanks



Jul 30 '08 #7

P: n/a
Markgoldin,

You could, but the problem with that is that you would have to read from
the stream one character at a time (or rather, one byte at a time,
converting to a character when you have enough bytes). The reason for this
is that if you have say, 10 characters left in the stream, and you issue a
read for 100 bytes, the call will block until more bytes come in on the
stream.

This is why putting the length prefix in is a better option.

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

"Markgoldin" <ma*************@yahoo.comwrote in message
news:eb**************@TK2MSFTNGP04.phx.gbl...
What I am trying to do is to read the whole lot into a buffer.
Can I somehow read untill a special character is met? Something like char
13?
That way I dont have to send a number of bytes to read.

Thanks

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e1*************@TK2MSFTNGP02.phx.gbl...
> Generally, you should post the code in the same thread. The reason
for this is that there can be a LOT of threads in a newsgroup and a lot
of messages.

Looking at the code you posted, how do you know how many total bytes
make up the message? In other words, when a message is sent, when do you
know the XML ends? In a situation like this, you should be sending the
length of the message first to indicate the number of bytes that make up
the message, and then read that number of bytes.

Also, it's not guaranteed that the Stream will return the number of
bytes that you request to read. Because of that, you might have to call
it multiple times. Check out Jon Skeet's site which goes into more
detail:

http://www.yoda.arachsys.com/csharp/readbinary.html

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

"Markgoldin" <ma*************@yahoo.comwrote in message
news:OC**************@TK2MSFTNGP06.phx.gbl...
>><Are there actual line breaks
that are being injected into the stream somehow
Yes, I think that is what happens. I am not sending line breaks at these
positions.

<What is the code that you are using to call from the stream?
I have my code posted in "Multiple socket clients" message.
If you can't see it I will post it again.

Thanks alot for help.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e4**************@TK2MSFTNGP04.phx.gbl...
Markgoldin,

What are the line breaks representing? Are there actual line breaks
that are being injected into the stream somehow, or does it symbolize
the breaks in what you are reading from the server?

What is the code that you are using to call from the stream? Are
you checking the return value to see that all of the bytes that you
requested to read are actually being read, or are you just assuming
that the bytes are being read completely?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Markgoldin" <ma*************@yahoo.comwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
>I am sending an XML data from not dontnet process to a .Net via socket
>listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all
the time.
What do I need to do to keep XML well formed?
>
Thanks
>




Jul 30 '08 #8

P: n/a
On Jul 30, 11:46*am, "Markgoldin" <markgoldin_2...@yahoo.comwrote:
My code is posted in my message "Multiple socket clients".
Let me know if you can't see it I will post it here.

Thanks for the help.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mac...@gmail.comwrote in
messagenews:c7**********************************@x 41g2000hsb.googlegroups..com...
On Jul 30, 11:19 am, "Markgoldin" <markgoldin_2...@yahoo.comwrote:


I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?
Thanks

can you post the code you are using to get it from the network stream?
Are you calling WriteLine somewhere?- Hide quoted text -

- Show quoted text -
post the code here
Jul 30 '08 #9

P: n/a
Here is code I am using to create a socket listener:
public void Run()

{

go = true;

Random rand = new Random();

// Buffer for reading data

Byte[] bytes = new Byte[1024];

String data = null;

while (go)

{

TcpClient tcpc = FromAnotherClass.tcpl.AcceptTcpClient(); //accept
connection

data = null;

// Get a stream object for reading and writing

NetworkStream stream = tcpc.GetStream();

// Loop to receive all the data sent by the client.

int i;

while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)

{

// Translate data bytes to a ASCII string.

data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);

// Process the data sent by the client.

if (data != "")

{

System.Console.WriteLine(data);

}

}

Thread.Sleep(1000 + rand.Next(2000));

}

}

"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:f8**********************************@r66g2000 hsg.googlegroups.com...
On Jul 30, 11:46 am, "Markgoldin" <markgoldin_2...@yahoo.comwrote:
My code is posted in my message "Multiple socket clients".
Let me know if you can't see it I will post it here.

Thanks for the help.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mac...@gmail.comwrote in
messagenews:c7**********************************@x 41g2000hsb.googlegroups.com...
On Jul 30, 11:19 am, "Markgoldin" <markgoldin_2...@yahoo.comwrote:


I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all the
time.
What do I need to do to keep XML well formed?
Thanks

can you post the code you are using to get it from the network stream?
Are you calling WriteLine somewhere?- Hide quoted text -

- Show quoted text -
post the code here
Jul 30 '08 #10

P: n/a
Ok, I looked int a link you have provided.
I am trying to adapt one of the examples from that link. Here is my code:

TcpClient tcpc = DataAdapterLauncher.tcpl.AcceptTcpClient(); //accept
connection
// Get a stream object for reading and writing
NetworkStream stream = tcpc.GetStream();
Byte[] buffer = new Byte[32768];
// Loop to receive all the data sent by the client.
int chunk;
int read = 0;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) != 0)
{
read += chunk;
System.Console.WriteLine(read);
// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
System.Console.WriteLine("read2");
// End of stream? If so, we're done
if (nextByte == -1)
{
// Process the data sent by the client.
// Translate data bytes to a ASCII string.
System.Console.WriteLine("read4");
break;
}
// Nope. Resize the buffer, put in the byte we've just
// read, and continue
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read++;
System.Console.WriteLine("read3");
}
}

In the Console it only says "read".
Here is the code fro the link:
/// <summary>
/// Reads data from a stream until the end is reached. The
/// data is returned as a byte array. An IOException is
/// thrown if any of the underlying IO calls fail.
/// </summary>
/// <param name="stream">The stream to read data from</param>
/// <param name="initialLength">The initial buffer length</param>
public static byte[] ReadFully (Stream stream, int initialLength)
{
// If we've been passed an unhelpful initial length, just
// use 32K.
if (initialLength < 1)
{
initialLength = 32768;
}

byte[] buffer = new byte[initialLength];
int read=0;

int chunk;
while ( (chunk = stream.Read(buffer, read, buffer.Length-read)) 0)
{
read += chunk;

// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();

// End of stream? If so, we're done
if (nextByte==-1)
{
return buffer;
}

// Nope. Resize the buffer, put in the byte we've just
// read, and continue
byte[] newBuffer = new byte[buffer.Length*2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read]=(byte)nextByte;
buffer = newBuffer;
read++;
}
}
// Buffer is now too big. Shrink it.
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
return ret;
}
I jsut can't figure out where my code is wrong.Can you please provide
help?Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:e1*************@TK2MSFTNGP02.phx.gbl...
Generally, you should post the code in the same thread. The reason for
this is that there can be a LOT of threads in a newsgroup and a lot of
messages.

Looking at the code you posted, how do you know how many total bytes
make up the message? In other words, when a message is sent, when do you
know the XML ends? In a situation like this, you should be sending the
length of the message first to indicate the number of bytes that make up
the message, and then read that number of bytes.

Also, it's not guaranteed that the Stream will return the number of
bytes that you request to read. Because of that, you might have to call
it multiple times. Check out Jon Skeet's site which goes into more
detail:

http://www.yoda.arachsys.com/csharp/readbinary.html

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

"Markgoldin" <ma*************@yahoo.comwrote in message
news:OC**************@TK2MSFTNGP06.phx.gbl...
><Are there actual line breaks
>>that are being injected into the stream somehow
Yes, I think that is what happens. I am not sending line breaks at these
positions.

<What is the code that you are using to call from the stream?
I have my code posted in "Multiple socket clients" message.
If you can't see it I will post it again.

Thanks alot for help.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:e4**************@TK2MSFTNGP04.phx.gbl...
>>Markgoldin,

What are the line breaks representing? Are there actual line breaks
that are being injected into the stream somehow, or does it symbolize
the breaks in what you are reading from the server?

What is the code that you are using to call from the stream? Are you
checking the return value to see that all of the bytes that you
requested to read are actually being read, or are you just assuming that
the bytes are being read completely?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Markgoldin" <ma*************@yahoo.comwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverdata>
</VFPData>
My problem is that sometimes it come out of a listner like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<finished>88</finished>
</serverda
ta>
</VFPData>
or like this:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>
<zone>BOXING</zone>
<status>Running</status>
<job>1000139233</job>
<sku>02219</sku>
<fini
shed>92</finished>
</serverdata>
</VFPData>
I am sure that the sending process sends data in a proper format all
the time.
What do I need to do to keep XML well formed?

Thanks



Aug 4 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.