| 484 | g_client->connections.erase_unsorted(iter); |
| 485 | } |
| 486 | void Update() |
| 487 | { |
| 488 | // Check for incoming signals, and dispatch them |
| 489 | if (signaling) |
| 490 | signaling->Poll(); |
| 491 | // Check callbacks |
| 492 | SteamNetworkingSockets()->RunCallbacks(); |
| 493 | ImGui::Begin("ControlPanel"); |
| 494 | if (!signaling) |
| 495 | { |
| 496 | static char name[256]; |
| 497 | ImGui::InputText("Name", name, 256); |
| 498 | ImGui::SameLine(); |
| 499 | if (ImGui::Button("SignIn")) |
| 500 | { |
| 501 | id.ParseString(name); |
| 502 | if (!id.IsInvalid()) |
| 503 | { |
| 504 | SteamNetworkingSockets()->ResetIdentity(&id); |
| 505 | SteamDatagramErrMsg errMsg; |
| 506 | // Create the signaling service |
| 507 | signaling = CreateTrivialSignalingClient(pszTrivialSignalingService, SteamNetworkingSockets(), errMsg); |
| 508 | if (signaling == nullptr) |
| 509 | SKR_LOG_FATAL(u8"Failed to initializing signaling client. %s", errMsg); |
| 510 | |
| 511 | SteamNetworkingUtils()->SetGlobalCallback_SteamNetConnectionStatusChanged(OnSteamNetConnectionStatusChanged); |
| 512 | |
| 513 | // Comment this line in for more detailed spew about signals, route finding, ICE, etc |
| 514 | // SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_LogLevel_P2PRendezvous, k_ESteamNetworkingSocketsDebugOutputType_Verbose ); |
| 515 | |
| 516 | // Currently you must create a listen socket to use symmetric mode, |
| 517 | // even if you know that you will always create connections "both ways". |
| 518 | // In the future we might try to remove this requirement. It is a bit |
| 519 | // less efficient, since it always triggered the race condition case |
| 520 | // where both sides create their own connections, and then one side |
| 521 | // decides to their theirs away. If we have a listen socket, then |
| 522 | // it can be the case that one peer will receive the incoming connection |
| 523 | // from the other peer, and since he has a listen socket, can save |
| 524 | // the connection, and then implicitly accept it when he initiates his |
| 525 | // own connection. Without the listen socket, if an incoming connection |
| 526 | // request arrives before we have started connecting out, then we are forced |
| 527 | // to ignore it, as the app has given no indication that it desires to |
| 528 | // receive inbound connections at all. |
| 529 | SKR_LOG_INFO(u8"Creating listen socket in symmetric mode, local virtual port %d\n", g_nVirtualPortLocal); |
| 530 | SteamNetworkingConfigValue_t opt; |
| 531 | opt.SetInt32(k_ESteamNetworkingConfig_SymmetricConnect, 1); // << Note we set symmetric mode on the listen socket |
| 532 | g_hListenSock = SteamNetworkingSockets()->CreateListenSocketP2P(g_nVirtualPortLocal, 1, &opt); |
| 533 | SKR_ASSERT(g_hListenSock != k_HSteamListenSocket_Invalid); |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | else |
| 538 | { |
| 539 | static char name[256]; |
| 540 | ImGui::InputText("Target", name, 256); |
| 541 | ImGui::SameLine(); |
| 542 | if (ImGui::Button("Connect")) |
| 543 | { |
no test coverage detected