Jump to content

Multiplayer Question


StOneDOes
 Share

Go to solution Solved by Einlander,

Recommended Posts

Hi guys,

I expected the new multiplayer system to be rather easy to use, as I've done manual connection and message sending before, but I can't seem to receive the connect message on the server end. I run the server application first, and then then the client application many seconds later, both on the same PC, but pMessage is always null. I'm also receiving a value in pPeer on the client end, so it seems like there is a successful connection. Can anyone see where I have gone wrong here?

Here's what I have at the moment.

Server:

int main()
{
	Window *pWindow = Window::Create( "Server", 100, 100, 400, 200, Window::Titlebar );
	Server *pServer = Server::Create();

	Message *pMessage;

	while( true )
	{
		if( pWindow->Closed() || pWindow->KeyHit( VK_ESCAPE ) )
			break;

		pMessage = pServer->Update();

		if( pMessage == nullptr )
			continue;

		if( pMessage->id == Message::Connect )
		{
			cout << "Player connected to the game." << endl;
		}

		pMessage->Release();
		pMessage = nullptr;
	}

	pServer->Release();
	pWindow->Release();

	return 0;
}

 

Client:

bool App::Start()
{
	m_pWindow = Window::Create( "Client", 100, 100, 800, 600, Window::Titlebar );
	
	Client *pClient = Client::Create();
	Peer *pPeer = pClient->Connect( "127.0.0.1" );

	return true;
}

 

Thanks in advance.

Link to comment
Share on other sites

2 hours ago, Einlander said:

I think the client needs to have it's own while loop with a Update() call. 

Thanks for your reply. That will be implemented on the client end when I'm ready, but shouldn't that only be required to actually receive a message from the server? I like to ensure things work step by step, so at the moment I want confirmation that there is an established connection.

Link to comment
Share on other sites

14 hours ago, Einlander said:

A connection is a message that it needs to send. IIRC it will do nothing until the client calls update.

Thanks for this. You were right, after calling Update() on the client, the server received the connect message, and the connect messag appeared on the Client end as well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...