public JobManagerFixture() { BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; System.Collections.IDictionary ClientTcpChannelProperties = new System.Collections.Hashtable(); ClientTcpChannelProperties["name"] = "ClientTcpChan"; ChannelServices.RegisterChannel( new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel(ClientTcpChannelProperties, new BinaryClientFormatterSinkProvider()), false); int port = 35010; System.Collections.IDictionary TcpChannelProperties = new System.Collections.Hashtable(); TcpChannelProperties["port"] = port; try { chan = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel(TcpChannelProperties, serverProv); ChannelServices.RegisterChannel(chan, false); server = new JobServerImpl(); serverRef = RemotingServices.Marshal(server, "JobServer"); server.handlersAdded.Set(); } catch (SocketException e) { if (!e.Message.StartsWith("Only one usage of each socket address")) { throw; } } }
static void Main(string[] argv) { try { Dictionary<string, string> settings = ParseArguments(argv); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; System.Collections.IDictionary ClientTcpChannelProperties = new System.Collections.Hashtable(); ClientTcpChannelProperties["name"] = "ClientTcpChan"; ChannelServices.RegisterChannel( new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel(ClientTcpChannelProperties, new BinaryClientFormatterSinkProvider()), false); //ChannelServices.RegisterChannel( // new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel(35010), false); //RemotingConfiguration.RegisterWellKnownServiceType(typeof(JobServer), // "JobServer", WellKnownObjectMode.Singleton); foreach (var item in ChannelServices.RegisteredChannels) { string name = item.ChannelName; } int port = 35010; // preferred string strPort = string.Empty; if (settings.TryGetValue("-P", out strPort)) { int.TryParse(strPort, out port); } port = GetPort(port); if (port == -1) { // there is no free tcp port } System.Collections.IDictionary TcpChannelProperties = new Dictionary<string, object>(); TcpChannelProperties["port"] = port; TcpChannelProperties["bindTo"] = System.Net.IPAddress.Loopback.ToString(); var tcpServerChannel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel(TcpChannelProperties, serverProv); ChannelServices.RegisterChannel(tcpServerChannel, false); JobServerImpl server = new JobServerImpl(); RemotingServices.Marshal(server, "JobServer"); JobManager manager = new JobManager(server, settings); Console.Out.WriteLine("JobManager has started"); manager.Text = "JobManager (Port:" + port.ToString() + ")"; Application.Run(manager); ChannelServices.UnregisterChannel(tcpServerChannel); } catch (Exception ex) { Console.Out.WriteLine("JobManager failed to start. Exception: {0}", ex); MessageBox.Show( ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } }