Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

void StunClient::Main (  ) [virtual]

User override function for the main execution routine of the thread. A descendent class must provide the code that will be executed in the thread within this function.

Note that the correct way for a thread to terminate is to return from this function.

Implements PThread.

Definition at line 64 of file main.cxx.

References PTrace::Blocks, PSTUNClient::CreateSocket(), PSTUNClient::CreateSocketPair(), PTrace::FileAndLine, PProcess::GetArguments(), PArgList::GetCount(), PSTUNClient::GetExternalAddress(), PIPSocket::GetLocalAddress(), PSTUNClient::GetNatTypeName(), PArgList::GetOptionCount(), PArgList::GetOptionString(), PArgList::HasOption(), PTrace::Initialise(), PArgList::Parse(), PTrace::Thread, and PTrace::Timestamp.

{
  PArgList & args = GetArguments();
  args.Parse("t-trace."       "-no-trace."
             "o-output:"      "-no-output.");

  PTrace::Initialise(args.GetOptionCount('t'),
                   args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL,
                   PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);

  WORD portbase, portmax;

  switch (args.GetCount()) {
    case 0 :
      cout << "usage: stunclient stunserver [ portbase [ portmax ]]\n";
      return;
    case 1 :
      portbase = 0;
      portmax = 0;
      break;
    case 2 :
      portbase = (WORD)args[1].AsUnsigned();
      portmax = (WORD)(portbase+9);
      break;
    default :
      portbase = (WORD)args[1].AsUnsigned();
      portmax = (WORD)args[2].AsUnsigned();
  }

  PSTUNClient stun(args[0], portbase, portmax, portbase, portmax);
  cout << "NAT type: " << stun.GetNatTypeName() << endl;

  PIPSocket::Address router;
  if (!stun.GetExternalAddress(router)) {
    cout << "Could not get router address!" << endl;
    return;
  }
  cout << "Router address: " << router << endl;

  PUDPSocket * udp;
  if (!stun.CreateSocket(udp)) {
    cout << "Cannot create a socket!" << endl;
    return;
  }

  PIPSocket::Address addr;
  WORD port;
  udp->GetLocalAddress(addr, port);
  cout << "Socket local address reported as " << addr << ":" << port << endl;

  delete udp;

  PUDPSocket * udp1, * udp2;
  if (!stun.CreateSocketPair(udp1, udp2)) {
    cout << "Cannot create socket pair" << endl;
    return;
  }

  udp1->GetLocalAddress(addr, port);
  cout << "Socket 1 local address reported as " << addr << ":" << port << endl;
  udp2->GetLocalAddress(addr, port);
  cout << "Socket 2 local address reported as " << addr << ":" << port << endl;

  delete udp1;
  delete udp2;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index