本文整理汇总了C++中KUser::get_port方法的典型用法代码示例。如果您正苦于以下问题:C++ KUser::get_port方法的具体用法?C++ KUser::get_port怎么用?C++ KUser::get_port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KUser
的用法示例。
在下文中一共展示了KUser::get_port方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//===================Main function=================
int main(int argc, char* argv)
{
int buf_len;
char main_buffer[MAX_MAIN_BUFFER];
KConnectionManager::Initialize();
KConnectionManager km = KConnectionManager();
KConnection* main_con = km.create_con(MAIN_PORT);
KLobby lobby = KLobby(&km);
//Handle signal
signal(SIGINT, TerminalHandler);
//Debug memory leak
#ifdef MEMORY_LEAK
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW );
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif//MEMORY_LEAK
sockaddr remote_addr;
while(Running) {//MainLoop
km.check(1,0);
if (main_con->has_data()) {
//Reinitialize buffer and len
buf_len = MAX_MAIN_BUFFER;
memset(main_buffer, 0, sizeof(main_buffer));
memset(&remote_addr, 0, sizeof(remote_addr));
//Recv data
buf_len = main_con->recv_data(main_buffer, buf_len, false);
main_con->get_raddr(&remote_addr);
if (strncmp("PING", main_buffer, MAX_MAIN_BUFFER) == 0) {//Echo message
//TODO:Send "PONG"
}
else if (strncmp("HELLO", main_buffer, 5) == 0) {
if (strncmp("0.83", main_buffer + 5, MAX_MAIN_BUFFER - 5) == 0) {
//XXX:Rember to delete user and game at list
KUser* nuser = lobby.new_user();
__PRINT("Port:%d\n", nuser->get_port());
snprintf(main_buffer, MAX_MAIN_BUFFER, "HELLOD00D%i", nuser->get_port());
main_con->send(main_buffer,sizeof(main_buffer));
}
else {
//Version error
//TODO:Send "VER"
}
}
else {
printf("Got an unexcept data:%s", main_buffer);
}
__PRINT("Recvdata:%s\n", main_buffer);
}
lobby.tick();
}
km.Release();
return 0;
}