コード例 #1
0
 /// <summary>
 /// Checks that the service is initialized.
 /// </summary>
 /// <param name="pokerService">The service to verify intitialization</param>
 private void CheckInitialized(PokerServiceProxy pokerService)
 {
     if (!CheckInitialized((ICommunicationObject)pokerService))
     {
         pokerService.InnerChannel.Faulted += new EventHandler(InnerChannel_Faulted);
         pokerService.InnerChannel.Closed  += new EventHandler(InnerChannel_Faulted);
     }
 }
コード例 #2
0
        /// <summary>
        /// Initializes the client. Opens connection to the specified server
        /// </summary>
        /// <param name="ipOrDns">The server IP or DNS address</param>
        /// <param name="port">The server port</param>
        /// <returns>
        /// The connected server details
        /// </returns>
        public ServerDetails Initialize(string ipOrDns, int port)
        {
            // the context with the current client
            InstanceContext context = new InstanceContext(this);
            // setup service channel
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true);

            binding.ReceiveTimeout          = TimeSpan.FromMinutes(10);
            binding.SendTimeout             = TimeSpan.FromMinutes(5);
            binding.ReliableSession.Ordered = true;
            EndpointAddress address = new EndpointAddress(string.Format("net.tcp://{0}:{1}/PokerService", ipOrDns, port));

            proxyService = new PokerServiceProxy(context, binding, address);


            // setup host channel
            binding   = new NetTcpBinding(SecurityMode.None);
            address   = new EndpointAddress(string.Format("net.tcp://{0}:{1}/PokerHost", ipOrDns, port));
            pokerHost = new PokerHostProxy(binding, address);
            pokerHost.Open();
            proxies.Add(pokerHost);

            // setup the broadcast channel
            binding = new NetTcpBinding(SecurityMode.None, true);
            binding.ReliableSession.Ordered = true;
            address        = new EndpointAddress(string.Format("net.tcp://{0}:{1}/PokerServiceBroadcast", ipOrDns, port));
            broadcastProxy = new PokerBroadcastProxy(context, binding, address);


            // setup the chat channel
            chatClient = new PokerChatClient(concreteClient);
            InstanceContext chatContext = new InstanceContext(chatClient);

            binding   = new NetTcpBinding(SecurityMode.None);
            address   = new EndpointAddress(string.Format("net.tcp://{0}:{1}/PokerRoomChat", ipOrDns, port));
            chatProxy = new PokerRoomChatProxy(chatContext, binding, address);


            // notify client of the connection
            concreteClient.NotifyConnectedToServer(new System.Net.IPEndPoint(System.Net.Dns.GetHostAddresses(ipOrDns)[0], port));
            ServerDetails result = pokerHost.GetServerDetails();

            concreteClient.NotifyRunningGame(result.Game, result.ConnectedPlayers);
            if (result.Game == ServerGame.FiveCardDraw && fiveCardConcreteClient == null)
            {
                result.CanConnect = canConnect = false;
            }
            return(result);
        }