Solved

VC++ MFC socket flush!!

Posted on 2003-11-04
3
1,396 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does std::atomic give me? 7 114
ASP.net build a IF/Then Walkthrough Guide 1 192
Add values of each row in an array 3 50
Beginner to Unreal Engine 4 5 62
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

863 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

18 Experts available now in Live!

Get 1:1 Help Now