C++ Program Flow: Sockets in an Object and the Main Function
- by jfm429
I have a rather tricky problem regarding C++ program flow using sockets.
Basically what I have is this: a simple command-line socket server program that listens on a socket and accepts one connection at a time.  When that connection is lost it opens up for further connections.
That socket communication system is contained in a class.  The class is fully capable of receiving the connections and mirroring the data received to the client.  However, the class uses UNIX sockets, which are not object-oriented.
My problem is that in my main() function, I have one line - the one that creates an instance of that object.  The object then initializes and waits.  But as soon as a connection is gained, the object's initialization function returns, and when that happens, the program quits.  How do I somehow wait until this object is deleted before the program quits?
  Summary:  
  
  
  main() creates instance of object  
  Object listens  
  Connection received  
  Object's initialization function returns  
  main() exits (!)  
  
  
  What I want is for main() to somehow delay until that object is finished with what it's doing (aka it will delete itself) before it quits.
Any thoughts?