I am facing a problem with multiplayer networking. All that I am doing is that I start a server by calling a function Mystartserver();
Before this function my variable named m_networkstarted is set as false but as soon as i start server once i set it to true.
Code:
Mystartserver(){
if (m_networkStarted)
return;
m_networkStarted = true;
GameEngine::startServer();
GameEngine::registerCallbackOnClientConnect(NetworkApp::clientConnectCb);}
While in my client i am doing folowing things
Code:
Myclient(const char* character, int spectator){
m_networkStarted = true;
const char* serverip = "127.0.0.1";
GameEngine::connectToServer(serverip);
if (m_networkStarted){
if(spectator > 0) {
m_spectator = true;
m_character = GameEngine::entityWorldID("Hans");
m_spectatorNum = spectator;
h3dSetupCameraView(GameEngine::entitySceneGraphID(m_camID),73.7f,4.0f / 3.0f, 0.1f, 1000.0f); }
else{
m_character = GameEngine::entityWorldID(character);
m_NPC = GameEngine::entityWorldID("Emilia"); }
if(!m_spectator) {
GameEngine::registerCallbackOnStateRequest(NetworkApp::stateRequestCb); }
if(m_spectator){
const char* serverip = "127.0.0.1";
GameEngine::connectToServer(serverip);
GameEngine::registerCallbackOnStateRequest(NetworkApp::stateRequestCb); }
}
else {return;}
}
Now when i am running the application (.exe) first time I am calling the server once. I run another (new) exe on same computer and then i call the client 1. It works and is connected to the server. Then I run 3rd .exe and then i call my client function again and this is the second time my client is called. so now when i do this i get the status on my screen that it is connected and after half a second its shows as it is Disconnected. What is the wrong in connecting a client that i am doing ?
Although client is running but it is not connected to the server. what possible reason could it be?
i just don't get why one client gets connected while when second client is connecting it is connected for half a second and then it is disconnected?