Clean up some minor details with the examples
* Change some of the stdout messages to prevent confusion. * Add port specification in server/client creation.
This commit is contained in:
parent
85822e682e
commit
6d1baf249b
|
@ -93,9 +93,10 @@ int main()
|
||||||
if(i == 's')
|
if(i == 's')
|
||||||
{
|
{
|
||||||
// Create a server and pass in a new instance of our callback class. The default
|
// 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();
|
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.
|
// Setting verbose to true makes irrNetLite spit out debug information to the console.
|
||||||
netManager->setVerbose(true);
|
netManager->setVerbose(true);
|
||||||
|
@ -119,26 +120,23 @@ int main()
|
||||||
// computer the client is on. Note that we just pass a value of 0 as our
|
// 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
|
// 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.
|
// packets. You can safely pass a value of 0 if this is the case.
|
||||||
net::INetManager* netManager = net::createIrrNetClient(0, "127.0.0.1");
|
net::INetManager* netManager = net::createIrrNetClient(0, "127.0.0.1", 60000);
|
||||||
|
|
||||||
// Enable debug messages.
|
// Enable debug messages.
|
||||||
netManager->setVerbose(true);
|
netManager->setVerbose(true);
|
||||||
|
|
||||||
|
|
||||||
// Here comes the fun part, while the client is connected we update the netManager
|
// 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
|
// 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,
|
// 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
|
// 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;
|
int i = 0;
|
||||||
// To send a packet, first you create an SOutPacket object.
|
|
||||||
net::SOutPacket packet;
|
|
||||||
|
|
||||||
while(netManager->getConnectionStatus() != net::EICS_FAILED && i < 10 )
|
while(netManager->getConnectionStatus() != net::EICS_FAILED && i < 10 )
|
||||||
{
|
{
|
||||||
|
|
||||||
// To send a packet, first you create an SOutPacket object.
|
// 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.
|
// Then you can use the streaming operator << to add new data to it.
|
||||||
packet << "Help I am stuck on a mountain!";
|
packet << "Help I am stuck on a mountain!";
|
||||||
|
@ -161,7 +159,6 @@ int main()
|
||||||
netManager->sendOutPacket(packet);
|
netManager->sendOutPacket(packet);
|
||||||
|
|
||||||
netManager->update(1000);
|
netManager->update(1000);
|
||||||
packet.clearData();
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,8 @@ int main()
|
||||||
// If they typed 's' they are the server else they are the client.
|
// If they typed 's' they are the server else they are the client.
|
||||||
if(i == 's')
|
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);
|
net::INetManager* netManager = net::createIrrNetServer(0);
|
||||||
|
|
||||||
// Pass in a server specific net callback.
|
// Pass in a server specific net callback.
|
||||||
|
@ -172,14 +173,18 @@ int main()
|
||||||
}
|
}
|
||||||
else
|
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
|
// You may want to change the ip address to a remote one and experiment
|
||||||
// with connecting to a remote host.
|
// with connecting to a remote host.
|
||||||
ClientNetCallback* clientCallback = new ClientNetCallback();
|
ClientNetCallback* clientCallback = new ClientNetCallback();
|
||||||
net::INetManager* netManager = net::createIrrNetClient(clientCallback, "127.0.0.1");
|
net::INetManager* netManager = net::createIrrNetClient(clientCallback, "127.0.0.1");
|
||||||
|
|
||||||
|
if (netManager->getConnectionStatus() == net::EICS_FAILED)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Print a simple menu.
|
// 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
|
<< "1. Change the cannon rotation." << std::endl
|
||||||
<< "2. Change the cannon power." << std::endl
|
<< "2. Change the cannon power." << std::endl
|
||||||
<< "3. Send a message." << std::endl;
|
<< "3. Send a message." << std::endl;
|
||||||
|
|
|
@ -181,8 +181,9 @@ int main()
|
||||||
// If they typed 's' they are the server else they are the client.
|
// If they typed 's' they are the server else they are the client.
|
||||||
if(i == 's')
|
if(i == 's')
|
||||||
{
|
{
|
||||||
// Create an irrNetLite server.
|
// Create an irrNetLite server. In this example we decide to listen on
|
||||||
net::INetManager* netManager = net::createIrrNetServer(0);
|
// port 65535, the highest port allowed.
|
||||||
|
net::INetManager* netManager = net::createIrrNetServer(0,65535);
|
||||||
|
|
||||||
// Pass in a server specific net callback.
|
// Pass in a server specific net callback.
|
||||||
ServerNetCallback* serverCallback = new ServerNetCallback(netManager);
|
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
|
// 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.
|
// won't be able to create anymore clients unless you restart the server.
|
||||||
ClientNetCallback* clientCallback = new ClientNetCallback();
|
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
|
// The clients in this example will simply send a custom greeting message
|
||||||
// when they connect and then wait and poll for events.
|
// when they connect and then wait and poll for events.
|
||||||
|
@ -213,7 +214,7 @@ int main()
|
||||||
if(netManager->getConnectionStatus() != net::EICS_FAILED)
|
if(netManager->getConnectionStatus() != net::EICS_FAILED)
|
||||||
{
|
{
|
||||||
// Print a simple menu.
|
// 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.
|
// Take the input.
|
||||||
std::string message;
|
std::string message;
|
||||||
|
|
Loading…
Reference in New Issue