empty string
-
for some reason the Encoding::ASCII->GetString always returns an empty string. While i was debugging it i verified that the buffer was full with data. in the client, i used this same method to return the string and it returned the data in the buffer (as expected). I'm not sure what i'm doing wrong here :doh:
StringBuilder ^sb = gcnew StringBuilder(); NetworkStream ^stream = (NetworkStream^)result->AsyncState; stream->EndRead(result); array ^buffer = gcnew array(1024); while(stream->DataAvailable) { int nRead = stream->Read(buffer, 0, 1024); sb->Append(Encoding::ASCII->GetString(buffer, 0, nRead)); //returns empty string every time. }
Don't be overcome by evil, but overcome evil with good
-
for some reason the Encoding::ASCII->GetString always returns an empty string. While i was debugging it i verified that the buffer was full with data. in the client, i used this same method to return the string and it returned the data in the buffer (as expected). I'm not sure what i'm doing wrong here :doh:
StringBuilder ^sb = gcnew StringBuilder(); NetworkStream ^stream = (NetworkStream^)result->AsyncState; stream->EndRead(result); array ^buffer = gcnew array(1024); while(stream->DataAvailable) { int nRead = stream->Read(buffer, 0, 1024); sb->Append(Encoding::ASCII->GetString(buffer, 0, nRead)); //returns empty string every time. }
Don't be overcome by evil, but overcome evil with good
I thought you get the number of bytes read from:
int nRead = stream->EndRead(result).
. Look at the sample code at: http://msdn2.microsoft.com/en-us/library/system.net.sockets.networkstream.endread(vs.80).aspx[^]."We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I thought you get the number of bytes read from:
int nRead = stream->EndRead(result).
. Look at the sample code at: http://msdn2.microsoft.com/en-us/library/system.net.sockets.networkstream.endread(vs.80).aspx[^]."We make a living by what we get, we make a life by what we give." --Winston Churchill
all i am doing there is calling the beginread to listen for any data and when it comes just do an end read and read the data in a loop synchronously. Here is a Screenshot[^] of what i am doing here. -- modified at 18:00 Monday 19th November, 2007 UPDATE: Pretty wierd...after troubleshooting it further, i got it to work. before i sent the data on the client side, i converted it to a base64 string and on the server side the encoding function worked. what the piece of data is that i am trying to send through is a serialized object using binaryformatter. I guess the GetString function didn't like the format of the data???
Don't be overcome by evil, but overcome evil with good