Solved

I have a function which sends a text string to a socket.

Posted on 2000-02-22
3
216 Views
Last Modified: 2013-11-20
I have a function which sends a text string to a socket.
I only want the function to return when I recieve a reply from the socket.

Any ideas how i do this?


further details

function x
{
  m_socket->Send("some text");

 return socket's (m_socket->Reply())
}


0
Comment
Question by:yakky
3 Comments
 
LVL 1

Accepted Solution

by:
BigOne earned 100 total points
ID: 2547708
Here's a slight modification, making some obvious assumptions

function x
{
  m_socket->Send("some text");
  CString cs;//(Or whatever your return type is)
  do
  {
     cs = m_socket->Reply();
  }while(cs.IsEmpty());//or equiv...
  return cs;
}

Good Skills




0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2548822
HI,

What about doing something like this
//Global flag
BOOL m_bReplyCame = FALSE;

//Function
function x
{
m_socket->Send("some text");
while(!m_bReplyCame);
}

//Usually there will be a thread to read the socket. In that thread
//if u got the reply then set that flag value to TRUE, so the while loop ends.
//and function returns. Take care to write that in a separate thread as u can notice, if socket is not read in separate thread, ur program is having a infinite loop!!!.

Try it out.
VinExpert
0
 

Author Comment

by:yakky
ID: 2549749
Thanks
yakky
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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

12 Experts available now in Live!

Get 1:1 Help Now