Exemple #1
0
        static void Main(string[] args)
        {
            // Declare all variables.
            string hostname = "127.0.0.1";
            int    port     = 3389;
            char   userInput;

            // request user input.
            Console.Write("Type Server(S) or Client(C): ");
            userInput = Console.ReadLine().ToUpper()[0];

            // Store the network type.
            //networkerType = (userInput == 'S') ? typeof(Server<SocketSession>) : typeof(Client<SocketSession>);

            string ipAddress = (userInput == 'S' ||
                                AddressHelper.CheckIfSamePublic(hostname))
                ? AddressHelper.GetLocalAddress()
                : hostname;

            if (userInput == 'S')
            {
                _networker = NetworkFactory.CreateServer <UnityServerSession>(ipAddress, port);
            }
            else
            {
                _networker = NetworkFactory.CreateClient <UnityServerSession>(ipAddress, port);
            }

            // Bind the networker to the current process.
            Bind(_networker);

            // Connect the networker.
            _networker.Connect();


            while (true)
            {
                if (_networker is Client <UnityServerSession> && _networker.IsConnected)
                {
                    ClientSend();
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }

            _tcpSessionWaitHandler.WaitOne();
        }