Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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