sending data thru a network stream

  • Thread starter Thread starter Gary Howe
  • Start date Start date
G

Gary Howe

I'm trying to send data from a PDA to a listener using TcpClient and
NetworkStream.

The problem is that is seems to not being recieving all the data. It
looks like there is a up limit of 45000 or so bytes.

Anyone having any ideas on how to send an unlimited or unknown ammount
of data from a PDA to a listener. your help would be greatly
appreciated.

Code information below
----------------------

Using this code to recieve the data.
if(netStream.CanWrite && netStream.CanRead)
{
string myCompleteMessage = "";
byte[] bytes = new byte[1024];
int numberOfBytesRead = 0;

do
{
numberOfBytesRead = netStream.Read(bytes, 0, bytes.Length);
myCompleteMessage = String.Concat(myCompleteMessage,
Encoding.ASCII.GetString(bytes, 0, numberOfBytesRead));

}while(netStream.DataAvailable);

Console.WriteLine(myCompleteMessage);

}

when netStream.DataAvailable becomes false total byte read are 45000
or so. When the code below sent 161,000 byes.

Byte[] byteResponse;
int Starthere = 0;
int ByteChunk = 1024;

while(Starthere < XMLSTR.Length)
{
if((Starthere + ByteChunk) < XMLSTR.Length)
{
byteResponse=
Encoding.ASCII.GetBytes(XMLSTR.ToString(Starthere,ByteChunk).ToCharArray());

client.GetStream().Write(byteResponse,0,byteResponse.Length);

Starthere += ByteChunk;
}
else
{
byteResponse =
Encoding.ASCII.GetBytes(XMLSTR.ToString(Starthere,XMLSTR.Length).ToCharArray());

client.SendBufferSize = byteResponse.Length;
client.GetStream().Write(byteResponse,0,byteResponse.Length);


Starthere = XMLSTR.Length + 10; // make sure starthere is
larger.
}
}


the data string being sent looks like.

<xmlset>
<item>
<name>Aname</name>
<value> a value</value>
</item>
<item>
<name>Aname</name>
<value> a value</value>
</item>
<item>
<name>Aname</name>
<value> a value</value>
</item>
</xmlset>
 
personally I try something like

int readed;
while((readed = stream.Read(buf, 0, buf.Length)) > 0)
{
}

but I have some problem for some data, too ... mmhh....
could it be something related to the speed of transfer and a small timeout
should be introduced when no more data is readed ? ...

according to some 'header' you should send first ...
 
Back
Top