private static void registerServer() { store = UserStore.loadStore(USER_STORE_FILE); if (store != null) Console.WriteLine("* Loaded " + store.userStore.Count + " users from store"); else { Console.WriteLine("* No users loaded from file"); store = UserStore.getNewStore(); //UserStore.saveStore(store, USER_STORE_FILE); } //Creating a custom formatter for a TcpChannel sink chain. BinaryServerFormatterSinkProvider providerNext = new BinaryServerFormatterSinkProvider(); providerNext.TypeFilterLevel = TypeFilterLevel.Full; TDIN_chatlib.ClientIPServerSinkProvider provider = new TDIN_chatlib.ClientIPServerSinkProvider(); provider.Next = providerNext; //Creating the IDictionary to set the port on the channel instance. IDictionary props = new Hashtable(); props["port"] = TDIN_chatlib.Constants.DEFAULT_SERVER_PORT; //Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.) TcpChannel chan = new TcpChannel(props, null, provider); // register the channel ChannelServices.RegisterChannel(chan, false); //Console.WriteLine("a: " + localAddress.IP + ", p: " + localAddress.PORT); Console.WriteLine("* Registering Server Object."); Console.WriteLine("* Running on port: " + TDIN_chatlib.Constants.DEFAULT_SERVER_PORT); RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatServer), TDIN_chatlib.Constants.SERVER_SERVICE, WellKnownObjectMode.Singleton); System.Console.ReadLine(); }
private void registerLocalClientServer() { //Creating a custom formatter for a TcpChannel sink chain. BinaryServerFormatterSinkProvider providerNext = new BinaryServerFormatterSinkProvider(); providerNext.TypeFilterLevel = TypeFilterLevel.Full; TDIN_chatlib.ClientIPServerSinkProvider provider = new TDIN_chatlib.ClientIPServerSinkProvider(); provider.Next = providerNext; //Creating the IDictionary to set the port on the channel instance. IDictionary props = new Hashtable(); props["port"] = 0; //Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.) TcpChannel chan = new TcpChannel(props, null, provider); // register the channel ChannelServices.RegisterChannel(chan, false); ChannelDataStore data = (ChannelDataStore)chan.ChannelData; MY_SERVICE_PORT = new Uri(data.ChannelUris[0]).Port; //IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName()); //string _ip = "127.0.0.1"; //foreach(IPAddress ip in IPHost.AddressList) //{ // if (ip.AddressFamily == AddressFamily.InterNetwork) // { // _ip = ip.ToString(); // // yep, dont stop and grab the last one on the list // } //} //localAddress = new TDIN_chatlib.InternalIPAddress( // _ip, // get IP // port // get the port // ); //Console.WriteLine("a: " + localAddress.IP + ", p: " + localAddress.PORT); Console.WriteLine("* Registering Server Subscription Object"); RemotingConfiguration.RegisterWellKnownServiceType(typeof(UserSubscribe), TDIN_chatlib.Constants.CLIENT_SUBSCRIBE_SERVICE, WellKnownObjectMode.Singleton); Console.WriteLine("* Registering Local Chat Object"); RemotingConfiguration.RegisterWellKnownServiceType(typeof(LocalClient), LOCAL_CHAT_SERVICE, WellKnownObjectMode.Singleton); }