Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. empty string

empty string

Scheduled Pinned Locked Moved Managed C++/CLI
data-structures
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    teejayem
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • T teejayem

      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

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • G George L Jackson

        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

        T Offline
        T Offline
        teejayem
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups