diff --git a/cocos/network/SocketIO.cpp b/cocos/network/SocketIO.cpp index 7aade376a0..5d662ebc65 100644 --- a/cocos/network/SocketIO.cpp +++ b/cocos/network/SocketIO.cpp @@ -1199,7 +1199,24 @@ SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& dele socket->addClient(path, c); socket->connectToEndpoint(path); - } + }else{ + CCLOG("SocketIO: disconnect previous client"); + c->disconnect(); + + CCLOG("SocketIO: recreate a new socket, new client, connect"); + SIOClientImpl* newSocket = nullptr; + SIOClient *newC = nullptr; + + newSocket = SIOClientImpl::create(host, port); + + newC = new (std::nothrow) SIOClient(host, port, path, newSocket, delegate); + + newSocket->addClient(path, newC); + + newSocket->connect(); + + return newC; + } } return c;