Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2000-02-22
3
Medium Priority
?
238 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
[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 1

Accepted Solution

by:
BigOne earned 300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 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