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. C / C++ / MFC
  4. (sockets) why does it do this?

(sockets) why does it do this?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestioncomsysadmintesting
3 Posts 3 Posters 0 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.
  • S Offline
    S Offline
    Sam 2006
    wrote on last edited by
    #1

    Hi, i've been trying to learn how to send data to other computers, i've looked at this article: http://www.codeproject.com/internet/Client\_Server.asp i can't understand why it "adds" new text to the old text. example: the server sends a message to a client saying "Testing" then the server sends another message to the client saying "Hi"... and the data recieved will read "Histing". it just replaces the letters... i am probably overlooking something very obvious, but could someone take a look and tell me why it is doing this? thanks in advance

    M N 2 Replies Last reply
    0
    • S Sam 2006

      Hi, i've been trying to learn how to send data to other computers, i've looked at this article: http://www.codeproject.com/internet/Client\_Server.asp i can't understand why it "adds" new text to the old text. example: the server sends a message to a client saying "Testing" then the server sends another message to the client saying "Hi"... and the data recieved will read "Histing". it just replaces the letters... i am probably overlooking something very obvious, but could someone take a look and tell me why it is doing this? thanks in advance

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      That's because when you reuse the buffer and receive two bytes in the second message, the bytes are stored at the beginning of the buffer. Pay attention to the number of bytes that the read-socket call returns, don't assume everything is null-terminated.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      1 Reply Last reply
      0
      • S Sam 2006

        Hi, i've been trying to learn how to send data to other computers, i've looked at this article: http://www.codeproject.com/internet/Client\_Server.asp i can't understand why it "adds" new text to the old text. example: the server sends a message to a client saying "Testing" then the server sends another message to the client saying "Hi"... and the data recieved will read "Histing". it just replaces the letters... i am probably overlooking something very obvious, but could someone take a look and tell me why it is doing this? thanks in advance

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        I think it's better to send (length(str)+1) so that you can simply send the null char also and no need to add a seperate null to the str at the receiving section. :) - NS -

        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