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. Sending string (text or array of character) trough a socket-connection.

Sending string (text or array of character) trough a socket-connection.

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpsysadmindata-structurestutorial
3 Posts 2 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
    SimCom
    wrote on last edited by
    #1

    Hello my best friends, I'm a beginner to Visual C++ programming, so I have some "stupid" questions for you and I hope you guys to help me. I'm working on my own very simple chatapplication, but I encounterd some problems. I've made a client and a server part, I've tested it out but I had the problem that I couldn't send a text string. My serverside establishes a connection with the clientside ( I know it because I put some control messages to be sure there is a connection). But when I try to send a peace of text, it does nothing except that it shows the sending text on my display and the receiver part shows nothing on the display. I used the following code to send a string: void CSimComDlg::OnSend() { m_Message.GetWindowText(strMESSAGE); m_pArOut->WriteString(strMESSAGE); m_pArOut->Flush(); m_MsgDsp.SetWindowText(_T(Name+":"+strMESSAGE+"\r\n")); strMESSAGE.Empty(); } And to read a received string: void CSimComDlg::ReadReceive() { m_pArIn->ReadString(strMESSAGE); m_MsgDsp.SetWindowText(_T("Chatter:"+strMESSAGE+"\r\n")); strMESSAGE.Empty(); } m_pArOut and m_pArIn are CArchive pointers (I use this in combination with CSocketFile to send data over internet). Is there something wrong with these codes? I've seen some other example codes on the internet, they include also the length of the message to send and they check also the buffer if there's more data coming in. But are they neccesary to put them in my code? I hope you can help me boyzz If my application works, I forget all my problems. If my application works, I forget all my problems.

    RaviBeeR 1 Reply Last reply
    0
    • S SimCom

      Hello my best friends, I'm a beginner to Visual C++ programming, so I have some "stupid" questions for you and I hope you guys to help me. I'm working on my own very simple chatapplication, but I encounterd some problems. I've made a client and a server part, I've tested it out but I had the problem that I couldn't send a text string. My serverside establishes a connection with the clientside ( I know it because I put some control messages to be sure there is a connection). But when I try to send a peace of text, it does nothing except that it shows the sending text on my display and the receiver part shows nothing on the display. I used the following code to send a string: void CSimComDlg::OnSend() { m_Message.GetWindowText(strMESSAGE); m_pArOut->WriteString(strMESSAGE); m_pArOut->Flush(); m_MsgDsp.SetWindowText(_T(Name+":"+strMESSAGE+"\r\n")); strMESSAGE.Empty(); } And to read a received string: void CSimComDlg::ReadReceive() { m_pArIn->ReadString(strMESSAGE); m_MsgDsp.SetWindowText(_T("Chatter:"+strMESSAGE+"\r\n")); strMESSAGE.Empty(); } m_pArOut and m_pArIn are CArchive pointers (I use this in combination with CSocketFile to send data over internet). Is there something wrong with these codes? I've seen some other example codes on the internet, they include also the length of the message to send and they check also the buffer if there's more data coming in. But are they neccesary to put them in my code? I hope you can help me boyzz If my application works, I forget all my problems. If my application works, I forget all my problems.

      RaviBeeR Online
      RaviBeeR Online
      RaviBee
      wrote on last edited by
      #2

      See this[^] excellent :cool: (imho) article. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

      S 1 Reply Last reply
      0
      • RaviBeeR RaviBee

        See this[^] excellent :cool: (imho) article. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        S Offline
        S Offline
        SimCom
        wrote on last edited by
        #3

        Thnx for the reply on my message, But actually I don't just want to copy some prepared codes where you just have to code for example: SendText("Hi how are you") and the rest goes by itself. I want to know what I've done vrong with my code and what do I have to change in my code or what code do I have to add in my code. I've seen some peaces of code using WriteString() and ReadString() with CArchive (wich needs also CSocketFile). I've seen also some codes using Send() and Receive of CSocket class. When I know how to use these codes I can alway encapsulated them just like NDK application you reffered it to. So I hope you can help me more about WriteString() and ReadString() and I hope other guys can help me too, you are all welcome. If my application works, I forget all my problems.

        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