
408 12. Network Programming
case 2:
str = console->getInput();
if (str == "")
return;
newPort = atoi(str.c_str());
if(newPort == 0)
newPort = netNS::DEFAULT_PORT;
if(newPort > netNS::MIN_PORT && newPort < 65536)
{
port = newPort;
step = 3;
}
else
console->print("Invalid port number");
console->clearInput();
break;
Listing 12.24(c). Step 2 in connecting to a server.
In step 2, we wait for the user to enter the port number. If they enter a valid number, we
save it in newPort and set the step variable to 3. ese steps are listed in Listing 12.24(c).
In step 3, we attempt to create a UDP client. If an error occurs, an error message is dis-
played, ...