Winsock C++ help: receiving data

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 1
Reputation: fritzpas is an unknown quantity at this point 
Solved Threads: 0
fritzpas fritzpas is offline Offline
Newbie Poster

Re: Winsock C++ help: receiving data

 
0
  #11
May 22nd, 2006
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.
Hello,

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
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 22
Reputation: Mr Violent is an unknown quantity at this point 
Solved Threads: 0
Mr Violent Mr Violent is offline Offline
Newbie Poster

Re: Winsock C++ help: receiving data

 
0
  #12
May 22nd, 2006
I didn't really solve the problem. I haven't found a good solution to this, although putting a slight delay on your sending function does seem to help--this is dependant on the speed of the program though.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 3
Reputation: Vex92 is an unknown quantity at this point 
Solved Threads: 0
Vex92 Vex92 is offline Offline
Newbie Poster

Re: Winsock C++ help: receiving data

 
0
  #13
Oct 9th, 2007
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
  1. FD_SET setWrite;
  2. FD_ZERO(&setWrite);
  3. FD_SET(m_socket, &setWrite);
  4. int n = m_socket + 1;
  5. if (select(n, 0, &setWrite, 0, 0) != SOCKET_ERROR) {
  6. string strSend = "all this packet information!!";
  7. int sz = strSend.size();
  8. send(m_socket, strSend.c_str(), sz, 0);
  9. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 1
Reputation: leo_yasir has a little shameless behaviour in the past 
Solved Threads: 0
leo_yasir leo_yasir is offline Offline
Newbie Poster

Re: Winsock C++ help: receiving data

 
-1
  #14
Jul 28th, 2009
Originally Posted by WolfPack View Post
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....
Can u tell me the exact code to access and read the data in that buffer.. i mean TCP buffer.. you can also mail me if u want to.
my email is <snip>
Last edited by John A; Jul 28th, 2009 at 4:26 am. Reason: removed email
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC