Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 73
Process filename extension 3 158
dog bark java program 15 82
noX challenge 17 77
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

10 Experts available now in Live!

Get 1:1 Help Now