private IChannel RegisterChannel(bool server = false) { var props = new Dictionary <string, string> { { "name", GcChannelName }, { "priority", Priority.ToString() } }; if (server) { props["port"] = Port.ToString(); if (!string.IsNullOrEmpty(ListenerInterface)) { props["interface"] = ListenerInterface; } } IChannel channel; switch (_channelType) { case GcChannelType.GHTTP: channel = new GenuineXHttpChannel(props, null, null); break; case GcChannelType.GTCP: channel = new GenuineTcpChannel(props, null, null); break; default: throw new NotImplementedException(_channelType.ToString()); } ChannelServices.RegisterChannel(channel, false); return(channel); }
internal static void StartServer(enumGC_Mode GC_Mode) { try { IDictionary props = new Hashtable(); switch (GC_Mode) { case enumGC_Mode.GC_TCP: Debug.WriteLine(" Starting GC_TCP Server"); props["name"] = "GTCP1"; props["priority"] = "100"; props["port"] = "8737"; // Null entries specify the default formatters. GenuineTcpChannel channelTCP = new GenuineTcpChannel(props, null, null); ChannelServices.RegisterChannel(channelTCP, false); break; case enumGC_Mode.GC_HTTP: Debug.WriteLine(" Starting GC_HTTP Server"); props["name"] = "ghttp"; props["priority"] = "100"; // Null entries specify the default formatters. GenuineHttpServerChannel channelHttp = new GenuineHttpServerChannel(props, null, null); ChannelServices.RegisterChannel(channelHttp, false); break; } // bind the server RemotingServices.Marshal(new ChatServer(), "ChatServer.rem"); Debug.WriteLine("Server has been started."); } catch (Exception ex) { Debug.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace); } }
private static IChannel RegisterChannel(bool server = false) { var props = new Dictionary <string, string> { { "name", "GTCP1" }, { "priority", "100" } }; if (server) { props["port"] = "8737"; } var channel = new GenuineTcpChannel(props, null, null); ChannelServices.RegisterChannel(channel, false); return(channel); }
static void Main(string[] args) { enumGC_Mode GC_Mode = enumGC_Mode.GC_HTTP; // setup .NET Remoting Console.WriteLine("Configuring Remoting environment..."); //System.Configuration.ConfigurationSettings.GetConfig("DNS"); GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler); IDictionary props = new Hashtable(); switch (GC_Mode) { case enumGC_Mode.GC_TCP: Console.WriteLine("GC_TCP Client connecting to Server..."); GenuineTcpChannel channelTCP = new GenuineTcpChannel(props, null, null); ChannelServices.RegisterChannel(channelTCP, false); RemoteHostUri = "gtcp://127.0.0.1:8737"; ChatClient.Nickname = "GC_TCP_ChatClient"; break; case enumGC_Mode.GC_HTTP: Console.WriteLine("GC_HTTP Client connecting to Server..."); props["name"] = "ghttp"; props["priority"] = "100"; GenuineHttpClientChannel channelHttp = new GenuineHttpClientChannel(props, null, null); ChannelServices.RegisterChannel(channelHttp, false); RemoteHostUri = "ghttp://localhost:49834"; // Note the full address will be determined by the server ChatClient.Nickname = "GC_HTTP_ChatClient"; break; } // bind client's receiver RemotingServices.Marshal(ChatClient.Instance, "MessageReceiver.rem"); for (;;) { try { // subscribe to the chat event lock (ChatClient.IChatServerLock) { ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom), RemoteHostUri + "/ChatServer.rem"); ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname); } for (;;) { Console.WriteLine("Enter a message to send or an empty string to exit."); string str = Console.ReadLine(); if (str.Length <= 0) { return; } ChatClient.IChatRoom.SendMessage(str); } } catch (Exception ex) { Console.WriteLine("\r\n\r\n---Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace); } Console.WriteLine("Next attempt to connect to the server will be in 3 seconds."); Thread.Sleep(3000); } }