Example #1
0
        public void InitializeServer()
        {
            connection = new Server();
            connection.PlayerCreated += new
                                        PlayerCreatedEventHandler(OnPlayerCreated);
            connection.PlayerDestroyed += new
                                          PlayerDestroyedEventHandler(OnPlayerDestroyed);
            connection.Receive   += new ReceiveEventHandler(OnDataReceive);
            connection.Disposing += new EventHandler(OnDisposing);


            if (!IServiceProviderValid(Address.ServiceProviderTcpIp))
            {
                MessageBox.Show("Невозможно создать TCP/IP службу поддержки",
                                "Выход", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            Address deviceAddress = null;

            deviceAddress = new Address();
            deviceAddress.ServiceProvider = Address.ServiceProviderTcpIp;
            deviceAddress.AddComponent(Address.KeyPort, SharedCode.DataPort);

            ApplicationDescription desc = new ApplicationDescription();

            desc.SessionName     = textBox1.Text;
            desc.MaxPlayers      = 2;
            desc.GuidApplication = SharedCode.ApplicationGuid;
            desc.Flags           = SessionFlags.ClientServer | SessionFlags.NoDpnServer;
            try
            {
                connection.Host(desc, deviceAddress);
                statusCreated(true);
                MessageBox.Show("Сессия создана",
                                "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("Невозможно создать сессию",
                                "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }