Fix issue with clients not properly disconnecting
When the client program exits it does not end its connection, which causes the server to leave the connection active until it times out. * Provide the disconnect event in the client destructor. * For easier testing, example 3 client no longer loops infinitely.
This commit is contained in:
parent
5d4859fff3
commit
bbc9bb3149
|
@ -1 +1,5 @@
|
||||||
*.o
|
*.o
|
||||||
|
*.a
|
||||||
|
examples/bin/*
|
||||||
|
!examples/bin/.gitkeep
|
||||||
|
!lib/.gitkeep
|
||||||
|
|
|
@ -9,7 +9,7 @@ When cloning use the `--recurse-submodules` flag to retrieve the enet and zlib l
|
||||||
|
|
||||||
`git clone --recurse-submodules https://github.com/rna88/irrnet.git`
|
`git clone --recurse-submodules https://github.com/rna88/irrnet.git`
|
||||||
|
|
||||||
Then run `make` in the `source/` directory to build the library.
|
Then run `make` in the `source/` directory to build the library, which will be placed in `lib/`.
|
||||||
|
|
||||||
|
|
||||||
## Building examples
|
## Building examples
|
||||||
|
@ -22,9 +22,9 @@ or to build them with optimizations:
|
||||||
|
|
||||||
`./linux_buildAllExamples.sh release`
|
`./linux_buildAllExamples.sh release`
|
||||||
|
|
||||||
The compiled binaries will be found in `examples/bin/`
|
The compiled binaries will be found in `examples/bin/`.
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Refer to `source/ReadMe.txt`
|
Refer to `source/ReadMe.txt`.
|
||||||
|
|
|
@ -103,6 +103,7 @@ public:
|
||||||
message += " has just left the building.";
|
message += " has just left the building.";
|
||||||
packet << message;
|
packet << message;
|
||||||
netManager->sendOutPacket(packet);
|
netManager->sendOutPacket(packet);
|
||||||
|
std::cout << "Client number " << playerId << " disconnected" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the packets, as usual.
|
// Handle the packets, as usual.
|
||||||
|
@ -213,11 +214,14 @@ int main()
|
||||||
netManager->sendOutPacket(packet);
|
netManager->sendOutPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here is the update loop, we will exit if there is a connection problem.
|
// Here is the update loop, we will exit if there is a connection problem
|
||||||
while(netManager->getConnectionStatus() != net::EICS_FAILED)
|
// or after running for 10 seconds.
|
||||||
|
int i = 0;
|
||||||
|
while(netManager->getConnectionStatus() != net::EICS_FAILED && i < 10)
|
||||||
{
|
{
|
||||||
// Here we update.
|
// Here we update.
|
||||||
netManager->update(1000);
|
netManager->update(1000);
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up.
|
// Clean up.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/libirrnet.a
BIN
lib/libirrnet.a
Binary file not shown.
|
@ -29,6 +29,14 @@ namespace irr
|
||||||
|
|
||||||
CNetManager::~CNetManager(void)
|
CNetManager::~CNetManager(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(mode == ENM_CLIENT)
|
||||||
|
{
|
||||||
|
ENetEvent event;
|
||||||
|
enet_peer_disconnect(peer, 0);
|
||||||
|
enet_host_service(host, &event, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if(host)
|
if(host)
|
||||||
enet_host_destroy(host);
|
enet_host_destroy(host);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue