| | |
Winsock C++ help: receiving data
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Mr Violent
That's not a bad idea at all--sending the EOL termination character and completely ignore the fact that packets may stack. However, I used a 1ms sleep on my client that was sending data to my server, and every message was seperated. My guess is that my client was sending too fast for send(), and the receiving was fine. I'm not sure what my limits are, but I may had to 'pad' my messages with a beginning and ending character to recognize the entirety of a message. Thanks for all the responses.
I have actually the same problem. I try to send Data ervery 10ms (is it to fast?) and i try to receive the data, but there is the same effect as you discribed at the biginning of the thread.
My Question now is: Is it possible that you tell us how you solved this problem eg. a code snippet?
Thank you and regards
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Solved Threads: 0
Can some one give me an example of a working winsock program that can send data and receive it because im on microsoft visual studios 2005 and it sais 1>.\Menu.cpp(126) : error C2065: 'm_socket' : undeclared identifier when i try to send data like this
C++ Syntax (Toggle Plain Text)
FD_SET setWrite; FD_ZERO(&setWrite); FD_SET(m_socket, &setWrite); int n = m_socket + 1; if (select(n, 0, &setWrite, 0, 0) != SOCKET_ERROR) { string strSend = "all this packet information!!"; int sz = strSend.size(); send(m_socket, strSend.c_str(), sz, 0); }
•
•
Join Date: Jul 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
stacking is not something unexpected or errornous in the socket API. the TCP IP protocol only guarantees that the data will reach the destination at the sent order. It may get sent in one try or multiple tries.The problem here is that you are using a 1024 size buffer. If the network IO buffer at the receiving end has data to fill this buffer it fills it with that data. The only way you can eliminate this problem is by using the knowledge of the properties of the data sent. If you know the length you can traverse the buffer using that length. Also you can use a buffer of exactly the required lenght.But even then if there isnot sufficient data, you may get a partially fileed buffer in one try and the rest of the data in the next. If you don't know the lenght, then you will have to use something like the line termination character when sending character data. This is the most reliable.
The best way to handle this problem is to use the 1024 size buffer for data collecting and process this data before displaying it.
Something like coding another loop to find the EOL character in the buffer, displaying the data upto that, and again searching for the EOL....
my email is <snip>
Last edited by John A; Jul 28th, 2009 at 4:26 am. Reason: removed email
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Works with one, not more.
- Next Thread: reStructure of code: include 2 void functions
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





