public void Initialize() { // Create game room NetworkBackgammonActivateServer myServer = new NetworkBackgammonActivateServer(); gameRoom = myServer.ActivateServer(port); }
/** * Activate/Deactivate server */ private bool ActivateServer(bool activate) { bool retval = false; try { if (activate) { if (m_turnOnServer == null) { m_turnOnServer = new NetworkBackgammonActivateServer(); m_server = m_turnOnServer.ActivateServer(m_portText.Text); } /* * // We need to use binary formatters, which allow the serialization of generic collections * BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); * serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; * BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider(); * * IDictionary props = new Hashtable(); * props["port"] = Convert.ToInt32(m_portText.Text); * * m_channel = new HttpChannel(props, clientProv, serverProv); * } * * ChannelServices.RegisterChannel(m_channel, false); * RemotingConfiguration.RegisterWellKnownServiceType( typeof(NetworkBackgammonRemoteGameRoom), "GameRoom", WellKnownObjectMode.Singleton); * * // Assign the instantiated remote server to the local server * MarshalByRefObject obj = (MarshalByRefObject)RemotingServices.Connect(typeof(NetworkBackgammonRemoteGameRoom), "http://127.0.0.1:" + m_portText.Text + "/GameRoom"); * m_server = obj as NetworkBackgammonRemoteGameRoom; */ // Register delegated listener as a listener of the server object retval = m_server.AddListener(this); m_activateServer.Text = "Stop Server"; m_portText.Enabled = false; // Log status message Log("Server Started..."); UpdateList(); } else { // Stop listening to the server m_server.RemoveListener(this); m_server.Shutdown(); m_server = null; if (m_channel != null) { ChannelServices.UnregisterChannel(m_channel); m_channel = null; } m_activateServer.Text = "Start Server"; m_portText.Enabled = true; // Log status message Log("Server Stopped..."); retval = true; } } catch (Exception ex) { Log(ex.Message); } return(retval); }