diff --git a/examples/01.Tutorial/main.cpp b/examples/01.Tutorial/main.cpp index 287ab40..1bc64c6 100644 --- a/examples/01.Tutorial/main.cpp +++ b/examples/01.Tutorial/main.cpp @@ -93,9 +93,10 @@ int main() if(i == 's') { // Create a server and pass in a new instance of our callback class. The default - // port that clients can connect to is set to 45000. + // port that clients can connect to is set to 45000, we'll set it to 60000. + // Recall that the valid port range is 1-65535. MyNetCallback* netCallback = new MyNetCallback(); - net::INetManager* netManager = net::createIrrNetServer(netCallback); + net::INetManager* netManager = net::createIrrNetServer(netCallback, 60000); // Setting verbose to true makes irrNetLite spit out debug information to the console. netManager->setVerbose(true); @@ -118,27 +119,24 @@ int main() // address ("127.0.0.1"), which basically means we are connecting to the same // computer the client is on. Note that we just pass a value of 0 as our // INetCallback, because the client in this example does no need to handle any - // packets. You can safely pass a value of 0 if this is the case. - net::INetManager* netManager = net::createIrrNetClient(0, "127.0.0.1"); + // packets. You can safely pass a value of 0 if this is the case. + net::INetManager* netManager = net::createIrrNetClient(0, "127.0.0.1", 60000); // Enable debug messages. netManager->setVerbose(true); + // Here comes the fun part, while the client is connected we update the netManager // and ask it to wait 1 second (1000 milliseconds) for new packets to arrive before // returning. Since the client in this example doesn't actually receive any packets, // the only purpose of the update call is to leave a 1 second interval between each - // packet we send. - + // packet we send. To prevent an infinite loop of messages we will quit after 10 messages. int i = 0; - // To send a packet, first you create an SOutPacket object. - net::SOutPacket packet; - while(netManager->getConnectionStatus() != net::EICS_FAILED && i < 10 ) { // To send a packet, first you create an SOutPacket object. - //net::SOutPacket packet; + net::SOutPacket packet; // Then you can use the streaming operator << to add new data to it. packet << "Help I am stuck on a mountain!"; @@ -161,7 +159,6 @@ int main() netManager->sendOutPacket(packet); netManager->update(1000); - packet.clearData(); i++; } diff --git a/examples/02.PacketIdentification/main.cpp b/examples/02.PacketIdentification/main.cpp index 153b049..47e0a27 100644 --- a/examples/02.PacketIdentification/main.cpp +++ b/examples/02.PacketIdentification/main.cpp @@ -156,7 +156,8 @@ int main() // If they typed 's' they are the server else they are the client. if(i == 's') { - // Create an irrNetLite server. + // Create an irrNetLite server. We won't specifiy a listen port, + // so the default port of 45000 will be used. net::INetManager* netManager = net::createIrrNetServer(0); // Pass in a server specific net callback. @@ -172,14 +173,18 @@ int main() } else { - // Create a client and pass in the client callback. + // Create a client and pass in the client callback. Since the server is + // using the default listen port of 45000, we don't need to pass it in. // You may want to change the ip address to a remote one and experiment // with connecting to a remote host. ClientNetCallback* clientCallback = new ClientNetCallback(); net::INetManager* netManager = net::createIrrNetClient(clientCallback, "127.0.0.1"); + + if (netManager->getConnectionStatus() == net::EICS_FAILED) + return 0; // Print a simple menu. - std::cout << "Example 1. What would you like to do?" << std::endl + std::cout << "You are connected! What would you like to do?" << std::endl << "1. Change the cannon rotation." << std::endl << "2. Change the cannon power." << std::endl << "3. Send a message." << std::endl; diff --git a/examples/03.ClientManagement/main.cpp b/examples/03.ClientManagement/main.cpp index fe195ac..09dc48f 100644 --- a/examples/03.ClientManagement/main.cpp +++ b/examples/03.ClientManagement/main.cpp @@ -181,8 +181,9 @@ int main() // If they typed 's' they are the server else they are the client. if(i == 's') { - // Create an irrNetLite server. - net::INetManager* netManager = net::createIrrNetServer(0); + // Create an irrNetLite server. In this example we decide to listen on + // port 65535, the highest port allowed. + net::INetManager* netManager = net::createIrrNetServer(0,65535); // Pass in a server specific net callback. ServerNetCallback* serverCallback = new ServerNetCallback(netManager); @@ -204,7 +205,7 @@ int main() // if you run all the clients from the same pc and ban one, you // won't be able to create anymore clients unless you restart the server. ClientNetCallback* clientCallback = new ClientNetCallback(); - net::INetManager* netManager = net::createIrrNetClient(clientCallback, "127.0.0.1"); + net::INetManager* netManager = net::createIrrNetClient(clientCallback, "127.0.0.1", 65535); // The clients in this example will simply send a custom greeting message // when they connect and then wait and poll for events. @@ -213,7 +214,7 @@ int main() if(netManager->getConnectionStatus() != net::EICS_FAILED) { // Print a simple menu. - std::cout << "Example 2. Please enter a greeting message:" << std::endl; + std::cout << "You are connected! Please enter a greeting message:" << std::endl; // Take the input. std::string message;