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