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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can't send text trough socket-connection, help me please!

Can't send text trough socket-connection, help me please!

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpsysadmintutorialquestion
4 Posts 3 Posters 2 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.

    L 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.

      L Offline
      L Offline
      lzzqqq
      wrote on last edited by
      #2

      CYourApp::Instance()//<<=====your app class { .... if (!AfxSocketInit()) { ::MessageBox(NULL,"Can't use socke!","Error",MB_OK); return false; } .... }

      S 1 Reply Last reply
      0
      • L lzzqqq

        CYourApp::Instance()//<<=====your app class { .... if (!AfxSocketInit()) { ::MessageBox(NULL,"Can't use socke!","Error",MB_OK); return false; } .... }

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

        Thnx for the reply, But what has this to do with sending test on the right way? I just want to know how I can send or receive text (in string-format) in its simplest form using CArchive and WriteString() and ReadString(). If my application works, I forget all my problems.

        E 1 Reply Last reply
        0
        • S SimCom

          Thnx for the reply, But what has this to do with sending test on the right way? I just want to know how I can send or receive text (in string-format) in its simplest form using CArchive and WriteString() and ReadString(). If my application works, I forget all my problems.

          E Offline
          E Offline
          El Corazon
          wrote on last edited by
          #4

          SimCom wrote: But what has this to do with sending test on the right way? I just want to know how I can send or receive text (in string-format) in its simplest form using CArchive and WriteString() and ReadString(). If my application works, I forget all my problems. what I think he is trying to say is check for error return values at every point, initialization to send/receive. Also since you did not include the initialize routine he showed, it may be as simple as initializing properly. The greater part of programming is learning how to find your own answers. Know what is wrong, and you can fix it. Run in debug mode, step through the operation, check error return values. Most of us do not have time to take your code, compile it into a full executable, discover the answers and give it back. I highly recommend running in debug mode. at least then you can say all the return values operate as if they are actually sending the information, but I am not receiving it. _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

          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