?
Solved

VC++ MFC socket flush!!

Posted on 2003-11-04
3
Medium Priority
?
1,475 Views
Last Modified: 2012-08-13
Hi,
I have a question in VC++.
I am using CSockets. I have a program where in i send messages through a socket in a for loop. However i need to know how to flush the messages so that before the next message the current message is passed on through the socket. The problem right now is sometimes the messages are being transferred one after another the way i would like and sometimes they are passed at once.
Thanks in advance.
S.
0
Comment
Question by:srik18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 9685250
What does this mean "they are passed at once"? CSocket::Send function is syncronous and returns only when send opertation completes. Please show your code and describe your problem with more details.
0
 
LVL 4

Assisted Solution

by:YuriPutivsky
YuriPutivsky earned 500 total points
ID: 9689304
In my experience I used to use the function
 BOOL _noDelay = 1;
::setsockopt(_number, IPPROTO_TCP, TCP_NODELAY, (char*)&_noDelay, sizeof(BOOL));
It should force Windows OS to flush TCP/IP buffer after send function completed. However on some computer after installation Windows OS patches it doesn't work.
So I fixed the problem with setting exact size for OUTBUF before calling send function
int buf_size = .... - you size here
::setsockopt(_number, SOL_SOCKET, SO_SNDBUF, (char*)&buf_size, sizeof(int));

_number is a socket number...
BTW for CSocket class you can use SetSockOpt member function instead.
Yuri.




0
 

Author Comment

by:srik18
ID: 9690512
Hi,
Thank you for your answers. I kind of solved my problem by doing a sleep in the for loop.
I think yuri's answer was more close but i am going ahead and splitting the points between the 2 of you.
AlexFm, what i meant by "they are passed at once" was that i had the sent() function in a for loop and hence instead of my messages being delivered  in each iteration...they were being sent all at once as it was not flushing to the socket in each iteration. I hope i am clear in what i explained.
Regards.
S.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question