Пример #1
0
        /// <summary>
        /// Connect to game server
        /// </summary>
        /// <param name="IP"></param>
        /// <returns></returns>
        public bool Connect(String IP)
        {

            // Create a pipeFactory
            DuplexChannelFactory<IMessage> pipeFactory =
                  new DuplexChannelFactory<IMessage>(
                      new InstanceContext(this),
                      new NetTcpBinding(),
                //new EndpointAddress(String.Format("net.tcp://{0}:8000/GameServer", IP)));
                      new EndpointAddress(String.Format("net.tcp://{0}:8000/GameServer", "localhost")));
            try
            {

                // Creating the communication channel
                pipeProxy = pipeFactory.CreateChannel();
                // register for events 
                pipeProxy.Subscribe();
                // join the game 
                myID = pipeProxy.join(me.Username, me.money, me.numOfGames, me.ID);
                if (pipeProxy.runningGame())
                {
                    pipeProxy.resetGame();
                }
                return true;
            }
            catch (Exception e)
            {
                
                return false;
            }
        }