MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / main

Function main

examples/example_chat.cpp:719–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

717}
718
719int main( int argc, const char *argv[] )
720{
721 bool bServer = false;
722 bool bClient = false;
723 int nPort = DEFAULT_SERVER_PORT;
724 SteamNetworkingIPAddr addrServer; addrServer.Clear();
725
726 for ( int i = 1 ; i < argc ; ++i )
727 {
728 if ( !bClient && !bServer )
729 {
730 if ( !strcmp( argv[i], "client" ) )
731 {
732 bClient = true;
733 continue;
734 }
735 if ( !strcmp( argv[i], "server" ) )
736 {
737 bServer = true;
738 continue;
739 }
740 }
741 if ( !strcmp( argv[i], "--port" ) )
742 {
743 ++i;
744 if ( i >= argc )
745 PrintUsageAndExit();
746 nPort = atoi( argv[i] );
747 if ( nPort <= 0 || nPort > 65535 )
748 FatalError( "Invalid port %d", nPort );
749 continue;
750 }
751
752 // Anything else, must be server address to connect to
753 if ( bClient && addrServer.IsIPv6AllZeros() )
754 {
755 if ( !addrServer.ParseString( argv[i] ) )
756 FatalError( "Invalid server address '%s'", argv[i] );
757 if ( addrServer.m_port == 0 )
758 addrServer.m_port = DEFAULT_SERVER_PORT;
759 continue;
760 }
761
762 PrintUsageAndExit();
763 }
764
765 if ( bClient == bServer || ( bClient && addrServer.IsIPv6AllZeros() ) )
766 PrintUsageAndExit();
767
768 // Create client and server sockets
769 InitSteamDatagramConnectionSockets();
770 LocalUserInput_Init();
771
772 if ( bClient )
773 {
774 ChatClient client;
775 client.Run( addrServer );
776 }

Callers

nothing calls this directly

Calls 10

PrintUsageAndExitFunction · 0.85
LocalUserInput_InitFunction · 0.85
NukeProcessFunction · 0.85
IsIPv6AllZerosMethod · 0.80
ParseStringMethod · 0.80
FatalErrorFunction · 0.70
ClearMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected