Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VC++ MFC socket flush!!

Posted on 2003-11-04
3
Medium Priority
?
1,498 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

604 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