Exemplo n.º 1
0
int Server::init()
{
	std::cout << "Server::init\n";

	// register message callbacks
	m_message_callbacks[ MSG_CLIENT_JOINGAME ] = &Server::client_join_game;

	m_server=grapple_server_init("testgame","1");
	grapple_server_ip_set(m_server,"127.0.0.1");   //OPTIONAL FUNCTION
	grapple_server_port_set(m_server,1234);
	grapple_server_protocol_set(m_server,GRAPPLE_PROTOCOL_UDP);
	grapple_server_session_set(m_server,"Play my game");
	grapple_server_start(m_server);

	std::cout << grapple_error_text(grapple_server_error_get(m_server)) << std::endl;

	return 0;
}
Exemplo n.º 2
0
grapple_server Server::initNetwork(const std::string& version, const std::string& name, const unsigned short port)
{
	grapple_server server = grapple_server_init("Pong2", version.c_str());
	grapple_server_sequential_set(server, GRAPPLE_NONSEQUENTIAL);
	grapple_server_port_set(server, port);
	grapple_server_protocol_set(server, GRAPPLE_PROTOCOL_UDP);
	grapple_server_maxusers_set(server, 2);
	grapple_server_session_set(server, name.c_str());
	grapple_server_start(server);

	//grapple_server_autoping(server, 5.0);

	grapple_error error = grapple_server_error_get(server);
	if (error != GRAPPLE_NO_ERROR) {
		std::cerr << "Error starting the client: " << grapple_error_text(error) << std::endl;
		return -1;
	}
	return server;
}