Solved

VC++ MFC socket flush!!

Posted on 2003-11-04
3
1,386 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
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 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 125 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now