Esempio n. 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();
        }
Esempio n. 2
0
        /// <summary>
        /// Create a game client and connect to a server.
        /// </summary>
        /// <param name="ip">The server's ip address.</param>
        /// <param name="tcpPort">The server's TCP port.</param>
        /// <param name="udpPort">The UDP port the client uses.</param>
        /// <returns>The game client.</returns>
        public Client CreateClient(ushort udpPort)
        {
            Client = new Client(NetworkFactory.CreateClient(udpPort));

            return(Client);
        }