Solved

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

Posted on 2000-02-22
3
219 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

685 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