0

I just started to learn ACE. I tried some of their simple examples and ran into a problem. This is my code:

int _tmain(int argc, _TCHAR* argv[])
{
    ACE_INET_Addr server_addr;
    ACE_SOCK_Acceptor acceptor;
    ACE_SOCK_Stream stream;

    if(server_addr.set(8888) == -1) return 1;
    if(acceptor.open(server_addr, 1) == -1) return 1;
    ....
}

It always return -1 when I call acceptor.open(...). I'm a bit new to network programming. There isn't anything wrong with the code as far as I can tell. I'm programming on a laptop with Wi-fi, does that make a difference? Also I have firewall turned on. (Tried turning it off, no difference).

This is the server side program. Do I have to configure my computer somehow?

Any help would be appreciated.

l3utterfly
  • 2,106
  • 4
  • 32
  • 58

1 Answers1

0

Fyi, here's a list of tutorials you can find online. I would recommend using the Reactor framework, an example is under $ACE_ROOT\examples\Reactor\TP_Reactor

But getting to your question, you don't need to use set() instead just use the constructor:

#include <ace/ACE.h>
#include <ace/SOCK_Acceptor.h>
#include <ace/INET_Addr.h>
#include <ace/Log_Msg.h>

int main(int argc, char *argv[])
{
  ACE_SOCK_Acceptor acceptor;
  ACE_INET_Addr server_addr(8888);

  // open a port using the acceptor; reuse the address later
  if (acceptor.open(server_addr, 1) == -1)
  {
    ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: Failed to open ")
                      ACE_TEXT ("listening socket. (errno = %i: %m)\n"), ACE_ERRNO_GET), -1);
  }

  // ...

  return 0;
}
Son-Huy Pham
  • 1,899
  • 18
  • 19