Solved

VC++ MFC socket flush!!

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

691 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