Inheritance: IServerFormatterSinkProvider, IServerChannelSinkProvider
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //TODO remove when PuppetMaster is implemented
            // myPort = 8086;
            //TODO remove after PuppetMaster is implemented
            //myURL = "tcp://localhost:"+myPort+"/broker";
            if (args.Length == 4)
            {
                new Broker(args[0], args[1], args[2], Int32.Parse(args[3]));
            }
            else
            {
                new Broker(args[0], args[1], Int32.Parse(args[2]));
            }

            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Hashtable();
            props["port"] = myPort;
            TcpChannel channel = new TcpChannel(props, null, provider);

            //TcpChannel channel = new TcpChannel(myPort);
            ChannelServices.RegisterChannel(channel, false);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteBroker), "broker", WellKnownObjectMode.Singleton);

            BrokerInterface rb = (BrokerInterface)Activator.GetObject(typeof(BrokerInterface), myURL);
            rb.ConnectFatherBroker(fatherURL);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private RemoteObject GetRemoteObject()
        {
            if (_remoteObject == null)
            {

                IDictionary tcpProperties = new Hashtable();

                BinaryClientFormatterSinkProvider tcpClientSinkProvider =
                    new BinaryClientFormatterSinkProvider();

                BinaryServerFormatterSinkProvider tcpServerSinkProvider =
                    new BinaryServerFormatterSinkProvider();

                tcpServerSinkProvider.TypeFilterLevel =
                    System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                tcpProperties["timeout"] = 5000;
                tcpProperties["port"] = 0;

                _tcpChannel = new TcpChannel(
                    tcpProperties,
                    tcpClientSinkProvider,
                    tcpServerSinkProvider);

                ChannelServices.RegisterChannel(_tcpChannel, false);

                _remoteObject = (RemoteObject)Activator.GetObject(
                               typeof(RemoteObject),
                               "tcp://127.0.0.1:9000/RO"
                               );
            }

            return _remoteObject;
        }
        //private Belikov.GenuineChannels.GenuineTcp.GenuineTcpChannel channel;
        public HTTPTwoWayRemotingClient(int listenPort, int keepAliveIntervalSeconds)
            : base(keepAliveIntervalSeconds)
        {
            /*IDictionary sProps = new Hashtable();
            sProps["algorithm"] = "3DES";
            sProps["requireSecurity"] = "true";
            sProps["connectionAgeLimit"] = "120";
            sProps["sweepFrequency"] = "60";*/

            BinaryServerFormatterSinkProvider binaryServerFormatSinkProvider = new BinaryServerFormatterSinkProvider();
            binaryServerFormatSinkProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            //SecureServerChannelSinkProvider secureServerSinkProvider = new SecureServerChannelSinkProvider(sProps, null);
            //secureServerSinkProvider.Next = binaryServerFormatSinkProvider;

            BinaryClientFormatterSinkProvider binaryClientFormatSinkProvider = new BinaryClientFormatterSinkProvider();
            //binaryClientFormatSinkProvider.Next = new SecureClientChannelSinkProvider(sProps, null);

            IDictionary props = new Hashtable();
            props["port"] = listenPort;
            //props["useIpAddress"] = false;
            //props["clientConnectionLimit"] = 1;
            //props["rejectRemoteRequests"] = false;
            //props["ConnectTimeout"] = 15000;
            //props["InvocationTimeout"] = 15000;
            //props["Priority"] = "100";

            //Belikov.GenuineChannels.Security.SecuritySessionServices.SetCurrentSecurityContext(new Belikov.GenuineChannels.Security.SecuritySessionParameters(Belikov.GenuineChannels.Security.SecuritySessionServices.DefaultContext.Name, Belikov.GenuineChannels.Security.SecuritySessionAttributes.ForceSync, TimeSpan.FromSeconds(15), Belikov.GenuineChannels.Connection.GenuineConnectionType.Persistent, null, TimeSpan.FromMinutes(5)));

            //channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel(props, binaryClientFormatSinkProvider, secureServerSinkProvider);
            channel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel(props, binaryClientFormatSinkProvider, binaryServerFormatSinkProvider);
            //channel = new System.Runtime.Remoting.Channels.Http.HttpChannel(props, binaryClientFormatSinkProvider, secureServerSinkProvider);
            //channel = new Belikov.GenuineChannels.GenuineTcp.GenuineTcpChannel(props, binaryClientFormatSinkProvider, binaryServerFormatSinkProvider);
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.DarkMagenta;
            Console.Clear();

            string dataServerName = args[0];
            int dataServerPort = Convert.ToInt32(args[1]);

            /*TcpChannel channel = new TcpChannel(metadataServerPort);
            ChannelServices.RegisterChannel(channel, true);*/

            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Hashtable();
            props["port"] = dataServerPort;
            props["timeout"] = 200000;

            TcpChannel channel = new TcpChannel(props, null, provider);
            ChannelServices.RegisterChannel(channel, true);

            //Registering DataServer service
            Console.WriteLine("Registering DataServer as " + dataServerName + " with port " + dataServerPort);
            DataServerRemoting dataServerRemotingObject = new DataServerRemoting(dataServerName, dataServerPort);
            RemotingServices.Marshal((DataServerRemoting)dataServerRemotingObject, dataServerName, typeof(DataServerRemoting));
            dataServerRemotingObject.register();
            /*RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(MetadataServerRemoting),
                metadataServerName,
                WellKnownObjectMode.Singleton); --> APAGAR EM PRINCIPIO*/
            Console.WriteLine("Registered!");

            System.Console.WriteLine("DataServer - " + dataServerName + " -<enter> to leave...");
            System.Console.ReadLine();
        }
Exemplo n.º 5
0
        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;
                }
            }
        }
 private void RegisterChannels()
 {
     BinaryServerFormatterSinkProvider binaryServerProv = new BinaryServerFormatterSinkProvider();
     binaryServerProv.TypeFilterLevel = TypeFilterLevel.Full;
     BinaryClientFormatterSinkProvider binaryClientProv = new BinaryClientFormatterSinkProvider();
     IDictionary props = new Hashtable();
     props["port"] = clientPort;
     props["name"] = server + ":" + serverPort;
     IPAddress[] serverIpAddresses = Dns.GetHostAddresses(server);
     IPAddress serverSelectedIP = null;
     foreach (IPAddress address in serverIpAddresses)
     {
         if (address.AddressFamily == AddressFamily.InterNetwork)
         {
             serverSelectedIP = address;
         }
     }
     if (serverSelectedIP != null)
     {
         IPAddress address = NetHelper.GetIpAddressFromTheSameNetworkAs(serverSelectedIP);
         if (address != null)
         {
             props["machineName"] = address.ToString();
         }
     }
     else
     {
         throw new Exception("Could not select an IP address for the server.");
     }
     chan = new TcpChannel(props, binaryClientProv, binaryServerProv);
     ChannelServices.RegisterChannel(chan);
 }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            RemotingConfiguration.ApplicationName = "CallbackRemoting";

            // 设置formatter
            BinaryServerFormatterSinkProvider formatter = new BinaryServerFormatterSinkProvider();
            formatter.TypeFilterLevel = TypeFilterLevel.Full;

            // 设置通道名称和端口
            IDictionary propertyDic = new Hashtable();
            propertyDic["name"] = "CustomTcpChannel";
            propertyDic["port"] = 8502;

            // 注册通道
            IChannel tcpChnl = new TcpChannel(propertyDic, null, formatter);
            ChannelServices.RegisterChannel(tcpChnl, false);

            // 注册类型
            Type t = typeof(Server);
            RemotingConfiguration.RegisterWellKnownServiceType(
                t, "ServerActivated", WellKnownObjectMode.Singleton);

            Console.WriteLine("Server running, model: Singleton\n");
            Console.ReadKey();
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            short port=23456;

            Console.WriteLine("USAGE: subserver <portnumber>");

            if(args.Length>1 && Int16.TryParse(args[1],out port) && port>1024){
                //OK, got good port
            } else {
                port = 23456; //default port
            }

            try {
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                IDictionary props = new Hashtable();
                props["port"] = port;

                TcpChannel chan = new TcpChannel(props, clientProv, serverProv);	//create the tcp channel
                ChannelServices.RegisterChannel(chan,false);	//register the tcp channel
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(subsharelib.subshareRemoteObject),"SUBSERVER",WellKnownObjectMode.Singleton);	//publish the remote object

                Console.WriteLine("SERVER STARTED AT PORT "+port);
            } catch (Exception ex) {
                Console.WriteLine("SERVER CAN NOT START! "+ex);
            }
            Console.Write("Press any key to exit . . . ");
            Console.ReadKey(true);
        }
Exemplo n.º 9
0
        public frmRCleint()
        {
            InitializeComponent();

            //************************************* TCP *************************************//
            // using TCP protocol
            // running both client and server on same machines
            //TcpChannel chan = new TcpChannel();
            //˫���ŵ�
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();
            props["port"] = 0;//���ն˿�(���)
            TcpChannel chan = new TcpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(chan,false);
            // Create an instance of the remote object
            remoteObject = (MyRemotableObject) Activator.GetObject(typeof(MyRemotableObject),"tcp://localhost:8080/HelloWorld");
            // if remote object is on another machine the name of the machine should be used instead of localhost.
            //************************************* TCP *************************************//
            wrapper = new EventWrapper();//�¼���װ������
            wrapper.LocalEvent += new ServerEventHandler(OnServerEvent);
            remoteObject.ServerEvent += new ServerEventHandler(wrapper.Response);
        }
Exemplo n.º 10
0
        public PuppetMasterForm()
        {
            InitializeComponent();

            //Inicializations
            puppet_master_history_TextBox.Text = "";
            dump_history_TextBox.Text = "";
            command_TextBox.Text = "";

            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Hashtable();
            props["port"] = 8400;
            props["timeout"] = 200000;

            channel = new TcpChannel(props, null, provider);
            ChannelServices.RegisterChannel(channel, true);

            clients = new Dictionary<string, Tuple<string, ClientInterface>>();
            metadataServers = new Dictionary<string, Tuple<string, MetadataServerInterface>>();
            dataServers = new Dictionary<string, Tuple<string, DataServerInterface>>();

            clientStartPort = 8100;
            metadataServerStartPort = 8200;
            dataServerStartPort = 8300;

            script = null;
        }
Exemplo n.º 11
0
        public EntryPoint(
            RemoteHooking.IContext context,
            String channelName,
            CaptureConfig config)
        {
            // Get reference to IPC to host application
            // Note: any methods called or events triggered against _interface will execute in the host process.
            _interface = RemoteHooking.IpcConnectClient<CaptureInterface>(channelName);

            // We try to ping immediately, if it fails then injection fails
            _interface.Ping();

            #region Allow client event handlers (bi-directional IPC)

            // Attempt to create a IpcServerChannel so that any event handlers on the client will function correctly
            IDictionary properties = new Hashtable();
            properties["name"] = channelName;
            properties["portName"] = channelName + Guid.NewGuid().ToString("N");
            // random portName so no conflict with existing channels of channelName

            var binaryProv =
                new BinaryServerFormatterSinkProvider();
            binaryProv.TypeFilterLevel = TypeFilterLevel.Full;

            var _clientServerChannel =
                new IpcServerChannel(properties, binaryProv);
            ChannelServices.RegisterChannel(_clientServerChannel, false);

            #endregion
        }
Exemplo n.º 12
0
        /// <summary>
        /// Sets up the services remoting channel
        /// </summary>
        public void Start()
        {
            try
            {
                System.Collections.Hashtable props = new System.Collections.Hashtable();
                props["typeFilterLevel"] = "Full";

                // Both formatters only use the typeFilterLevel property
                BinaryClientFormatterSinkProvider cliFormatter = new BinaryClientFormatterSinkProvider(props, null);
                BinaryServerFormatterSinkProvider srvFormatter = new BinaryServerFormatterSinkProvider(props, null);

                // The channel requires these to be set that it can found by name by clients
                props["name"] = "SyslogConsole";
                props["portName"] = "SyslogConsole";
                props["authorizedGroup"] = "Everyone";

                // Create the channel
                channel = new IpcChannel(props, cliFormatter, srvFormatter);
                channel.IsSecured = false;

                // Register the channel in the Windows IPC list
                ChannelServices.RegisterChannel(channel, false);

                // Register the channel for remoting use
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClientMethods), "Server", WellKnownObjectMode.Singleton);

                // Assign the event to a handler
                Listener.MessageReceived += new Listener.MessageReceivedEventHandler(Listener_MessageReceived);
            }
            catch (Exception ex)
            {
                EventLogger.LogEvent("Could not create a named pipe because: " + ex.Message + Environment.NewLine + "Communication with the GUI console will be disabled.",
                    System.Diagnostics.EventLogEntryType.Warning);
            }
        }
Exemplo n.º 13
0
Arquivo: Login.cs Projeto: Hourani/GDS
        private void RegisterRemoting()
        {
            {
                try
                {
                    BinaryServerFormatterSinkProvider server_provider = new BinaryServerFormatterSinkProvider();
                    server_provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                    BinaryClientFormatterSinkProvider client_provider = new BinaryClientFormatterSinkProvider();
                    IDictionary properties = new Hashtable();

                    properties["port"] = "0";

                    TcpChannel channel = new TcpChannel(properties, client_provider, server_provider);
                    ChannelServices.RegisterChannel(channel, false);

                    user = (IUser)Activator.GetObject(typeof(IUser), "tcp://localhost:9998/UserHandeling");
                    portal = (IPortal)Activator.GetObject(typeof(IPortal), "tcp://localhost:9998/PortalHandeling");
                    ftserver = (IFTserver)Activator.GetObject(typeof(IFTserver), "tcp://localhost:9998/TransferHandeling");
                }
                catch (RemotingException e)
                {
                    MessageBox.Show("Connection Error");
                }
            }
        }
Exemplo n.º 14
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            setServiceXml();
            btnStart.Enabled = false;
            
            try
            {
                Setting.Load();
                BinaryServerFormatterSinkProvider binaryServerFormatterSinkProvider = new BinaryServerFormatterSinkProvider();
                BinaryClientFormatterSinkProvider clientSinkProvider = new BinaryClientFormatterSinkProvider();
                binaryServerFormatterSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;

                IDictionary dic = new Dictionary<string, int>();
                dic.Add("port", Setting.Instance.Port);

                TcpChannel channel = new TcpChannel(dic, clientSinkProvider, binaryServerFormatterSinkProvider);
                ChannelServices.RegisterChannel(channel, false);
                List<IRemoteService> list = ServicesManager.GetTypeFromAssembly<IRemoteService>();
                foreach (IRemoteService service in list)
                {
                    service.RegisterService();
                }
                btnStop.Enabled = true;
            }
            catch (Exception ex)
            {
                btnStart.Enabled = true;
                throw ex;
            }
        }
Exemplo n.º 15
0
        public IChannelReceiver CreateServerChannel(string name, Uri uri)
        {
            var sink = new BinaryServerFormatterSinkProvider();
            sink.TypeFilterLevel = TypeFilterLevel.Full;

            return new TcpServerChannel(name, uri.Port, sink);
        }
Exemplo n.º 16
0
        public static void launchDataServer(int port, string masterUrl)
        {
            BinaryServerFormatterSinkProvider serverProv =
                new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = TypeFilterLevel.Full;

            IDictionary propBag = new Hashtable();
            propBag["port"] = port;
            propBag["typeFilterLevel"] = TypeFilterLevel.Full;
            propBag["name"] = "tcp" + port;  // here enter unique channel name

            TcpChannel channel = new TcpChannel(propBag, null, serverProv);
            ChannelServices.RegisterChannel(channel, false);
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(RemoteDataServer),
                "RemoteDataServer",
                WellKnownObjectMode.Singleton);

            RemoteDataServer.master = (IMasterServer)Activator.GetObject(
                typeof(IMasterServer),
                masterUrl);

            RemoteDataServer.myUrl = "tcp://" + Dns.GetHostName() + ":" + port + "/RemoteDataServer";
            bool reg = RemoteDataServer.master.RegisterDataServer(RemoteDataServer.myUrl);

            if (reg)
            {
                Console.WriteLine("Connected to MasterServer");
            }
        }
Exemplo n.º 17
0
        public RemotingHostServer(Machine machine, int port, string name)
            : base(machine)
        {
            this.port = port;
            this.name = name;

            // TODO review this name, get machine name
            this.hostname = "localhost";

            // According to http://www.thinktecture.com/resourcearchive/net-remoting-faq/changes2003
            // in order to have ObjRef accessible from client code
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            IDictionary props = new Hashtable();
            props["port"] = port;

            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            if (!registered)
            {
                ChannelServices.RegisterChannel(channel, false);
                registered = true;
            }

            // end of "according"

            // TODO review other options to publish an object
            this.objref = RemotingServices.Marshal(this, name);
        }
Exemplo n.º 18
0
        public void Expose(Uri uri)
        {
            this.VerifyRemoteType();

            var properties = new Hashtable() { { "port", uri.Port }, { "name", "channel_" + uri.Port } };
            //TODO:设置windows权限
            if (uri.Scheme.Equals("tcp"))
            {
                var provider = new BinaryServerFormatterSinkProvider() { TypeFilterLevel = TypeFilterLevel.Full };
                ChannelServices.RegisterChannel(new TcpChannel(properties, null, provider), false);
            }
            else if (uri.Scheme.Equals("http"))
            {
                var provider = new SoapServerFormatterSinkProvider() { TypeFilterLevel = TypeFilterLevel.Full };
                ChannelServices.RegisterChannel(new HttpChannel(properties, null, provider), false);
            }
            else
                throw new InvalidOperationException("不支持该通道:" + uri);

            this.SetRemotingConfiguration();
            //facade无状态,使用singleton减少对象创建消耗
            //TODO:SAO+连接池对比singleton的高并发下连接创建性能?
            RemotingConfiguration.RegisterWellKnownServiceType(this.RemoteType
                , uri.LocalPath.TrimStart('/')
                , WellKnownObjectMode.Singleton);

            this._log.InfoFormat("将服务节点通过.Net Remoting暴露在地址{0},类型为{1}", uri, this.RemoteType);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Set up remoting communication channels.
        /// </summary>
        private void SetupChannels()
        {
            lock (m_hostLock)
            {
                // If channels are not set up yet, set them up.
                if (m_serverChannel == null)
                {
                    Debug.Assert(m_clientChannel == null);

                    // This channel is used for debugging session, when TA connects to authoring vs instance.
                    BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                    serverProvider.TypeFilterLevel = TypeFilterLevel.Full;  // Enable remoting objects as arguments.
                    Hashtable props = new Hashtable();
                    string channelNamePrefix = "ExcelTestHostAddin_";
                    string serverChannelName = channelNamePrefix + Guid.NewGuid() + "_ServerChannel";
                    props["name"] = serverChannelName;
                    props["portName"] = serverChannelName;           // Must be different from client's port.
                    // Default IpcChannel security is: allow for all users who can authorize on this machine.
                    props["authorizedGroup"] = WindowsIdentity.GetCurrent().Name;
                    m_serverChannel = new IpcServerChannel(props, serverProvider);
                    ChannelServices.RegisterChannel(m_serverChannel, false);

                    // This channel is used for connecting to both authoring and host side VS.
                    m_clientChannel = new IpcClientChannel(channelNamePrefix + Guid.NewGuid() + "_ClientChannel", new BinaryClientFormatterSinkProvider());
                    ChannelServices.RegisterChannel(m_clientChannel, false);
                }
            }
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure(@"../../App.config", true);

            KeyValuePair<int, int> idAndPort;
            System.Console.WriteLine("Bootstrapping...");
            TcpChannel channel = new TcpChannel();
            ChannelServices.RegisterChannel(channel, false);
            System.Console.WriteLine("Registered Channel @random");

            string address = System.IO.File.ReadAllText(@"../../../mServerLocation.dat");

            MasterInterface mServer = (MasterInterface)Activator.GetObject(typeof(MasterInterface), address);
            idAndPort = mServer.RegisterTransactionalServer(getIP());

            System.Console.WriteLine("Registered at Master");
            ChannelServices.UnregisterChannel(channel);
            System.Console.WriteLine("Unbinding old port");

            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Hashtable();
            props["port"] = idAndPort.Value;

            channel = new TcpChannel(props, null, provider);

            ChannelServices.RegisterChannel(channel, false);
            System.Console.WriteLine("Registered Channel @" + idAndPort.Value);
            TransactionalServer ts = new TransactionalServer(idAndPort.Key, mServer, "tcp://"+getIP()+":"+idAndPort.Value+"/Server");
            RemotingServices.Marshal(ts, "Server", typeof(TransactionalServer));
            System.Console.WriteLine("SERVER ON");
            System.Console.WriteLine("Server: " + idAndPort.Key + " Port: " + idAndPort.Value + " IP: "+ getIP());
            System.Console.ReadLine();
        }
        private void CreateCommunicationChannel()
        {
            BinaryServerFormatterSinkProvider binaryServerProv = new BinaryServerFormatterSinkProvider();
            binaryServerProv.TypeFilterLevel = TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider binaryClientProv = new BinaryClientFormatterSinkProvider();

            IDictionary props = new Hashtable();
            props["port"] = settings.Port;
            props["authenticationMode"] = "IdentifyCallers";


            //HttpChannel chan = new HttpChannel(props, binaryClientProv, binaryServerProv); 
            try
            {
                TcpChannel chan = new TcpChannel(props, binaryClientProv, binaryServerProv);
                ChannelServices.RegisterChannel(chan, false);
                if (chan == null)
                {
                    new WindowsServiceLog().WriteEntry(
                            string.Format("Could not start server with port {0}", settings.Port));
                    Process.GetCurrentProcess().Kill();
                }
            }
            catch (SocketException e)
            {
                new WindowsServiceLog().WriteEntry(
                        string.Format("Could not start server. Application port {1} is using by another application. Error message: {0}",
                                                    e.Message, settings.Port));
                Process.GetCurrentProcess().Kill();
            }
        }
		/// <summary>
		///  Create a TcpChannel with a given name, on a given port.
		/// </summary>
		/// <param name="port"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		private static TcpChannel CreateTcpChannel( string name, int port, int limit )
		{
			ListDictionary props = new ListDictionary();
			props.Add( "port", port );
			props.Add( "name", name );
			props.Add( "bindTo", "127.0.0.1" );

			BinaryServerFormatterSinkProvider serverProvider =
				new BinaryServerFormatterSinkProvider();

            // NOTE: TypeFilterLevel and "clientConnectionLimit" property don't exist in .NET 1.0.
			Type typeFilterLevelType = typeof(object).Assembly.GetType("System.Runtime.Serialization.Formatters.TypeFilterLevel");
			if (typeFilterLevelType != null)
			{
				PropertyInfo typeFilterLevelProperty = serverProvider.GetType().GetProperty("TypeFilterLevel");
				object typeFilterLevel = Enum.Parse(typeFilterLevelType, "Full");
				typeFilterLevelProperty.SetValue(serverProvider, typeFilterLevel, null);

//                props.Add("clientConnectionLimit", limit);
            }

			BinaryClientFormatterSinkProvider clientProvider =
				new BinaryClientFormatterSinkProvider();

			return new TcpChannel( props, clientProvider, serverProvider );
		}
Exemplo n.º 23
0
        protected override void OnStart(string[] args)
        {
			Status("", true);
			Status("The ChatServer is initializing...", true);

            //log service initializing
            _port = SelectServerPort();
			Status("Done SelectServerPort...", true);
			//_server = ChatServer.Factory(_port);
            
			//_backgroundThread = new Thread(new ThreadStart(this.RunServer));
			//_backgroundThread.Start();
			//LogApplicationEvent("Start", "The ChatServer has successfully started up on port " + _port);
			
			LifetimeServices.LeaseTime = TimeSpan.FromDays(365);
			LifetimeServices.RenewOnCallTime = TimeSpan.FromDays(365);


			//Set up the channel details
			BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
			provider.TypeFilterLevel = TypeFilterLevel.Full;
			Status("Done BinaryServerFormatterSinkProvider...", true);

			string address = ChatServer.ChatServerIp;// ChatServer.GetMyIP();
			Hashtable props = new Hashtable();
			props.Add("port", _port);
			props.Add("bindTo", address);
			props.Add("name", "Address:" + address + ":" + _port);//this needs to be unique
			Status("Init on address:" + address + ":" + _port, true);
			
			//Create the channel
			TcpServerChannel chan = new TcpServerChannel(props, provider);
			Status("Done TcpServerChannel...", true);

			//register it
			ChannelServices.RegisterChannel(chan, false);
			Status("Done RegisterChannel", true);

			//register the object as a service
			RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatServer), "Reg", WellKnownObjectMode.Singleton);
			Status("Done RegisterWellKnownType", true);

			_server = new ChatServer(new ChatServer.StatusDelegate(Status));
			Status("Done ChatServer...", true);
			
			RemotingServices.Marshal(_server, "Reg");
			Status("Done RemotingServices.Marshal...", true);
			
			//_server.Setup(_port);
			Status("Done Setup...", true);

			_backgroundThread = new Thread(new ThreadStart(this.RunServer));
			_backgroundThread.Start();
			Status("Done Start...", true);

			//LogApplicationEvent("Start", "The ChatServer has successfully started up on port " + _port);

            
        }
Exemplo n.º 24
0
        private static bool SetupInterop()
        {
            IpcChannel ipcChannel = null;
            System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            try
            {
                Hashtable ipcProps = new Hashtable();
                ipcProps["portName"] = "SysCAD.ReactionEditor";
                ipcChannel = new IpcChannel(ipcProps, null, serverProv);
                ChannelServices.RegisterChannel(ipcChannel, false);
                interopMessenger = new InteropMessenger();
                RemotingServices.Marshal(interopMessenger, "interopMessenger");
                ResponsibleForChannel = true;
            }
            catch
            {
                try
                {
#if true           //Tests where the client would also register a channel...
                    Hashtable props = new Hashtable();
                    props["portName"] = "Remoting" + new Random().Next().ToString();
                    ipcChannel = new IpcChannel(props, null, serverProv);
                    ChannelServices.RegisterChannel(ipcChannel, false);
#endif

                    interopMessenger = Activator.GetObject(typeof(InteropMessenger), "ipc://SysCAD.ReactionEditor/interopMessenger") as InteropMessenger;
                    string directory = "";
                    foreach (string s in Args)
                        try  //Because GetDirectoryName has a few exceptions it likes to throw.
                        {
                            if (Directory.Exists(s) || File.Exists(s))
                            {
                                directory = Directory.Exists(s) ? s : 
                                    Path.GetDirectoryName(s);
                                if (directory == "")
                                    directory = Path.GetPathRoot(Path.GetDirectoryName(s));
                                break;
                            }
                        }
                        catch { }
                    bool alreadyOpen = Program.interopMessenger.AlreadyOpen(directory);
                    if (alreadyOpen)
                    {
                        interopMessenger.SendStrings(directory, Args);
                        return false;
                    }
                    //Check if it is a session ended message: If it is, don't start the application:
                    foreach (string s in Args)
                        if (s.ToLower() == "/sessionended")
                            return false;
                }
                catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            }
            return true;
        }
Exemplo n.º 25
0
		private static void SetupRemoting(int port) {
			BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
			BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider { TypeFilterLevel = TypeFilterLevel.Full };
			IDictionary props = new Hashtable();
			props["port"] = port;
			Logger.Info("Initializing on port " + port + "...");
			TcpChannel chan = new TcpChannel(props, clientProvider, serverProvider);
			ChannelServices.RegisterChannel(chan, false);
		}
Exemplo n.º 26
0
		public static void RegisterRemotingChannel ()
		{
			IDictionary dict = new Hashtable ();
			BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
			BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
			dict ["port"] = 0;
			serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
			ChannelServices.RegisterChannel (new TcpChannel (dict, clientProvider, serverProvider), false);
		}
Exemplo n.º 27
0
		static void StartServer(AssemblyService service, string name, string uri) {
			var props = new Hashtable();
			props["portName"] = name;
			var provider = new BinaryServerFormatterSinkProvider();
			provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
			var channel = new IpcServerChannel(props, provider);
			ChannelServices.RegisterChannel(channel, false);
			RemotingServices.Marshal(service, uri);
		}
        private static IServerChannelSinkProvider CreateServerChannelSinkProvider()
        {
            IDictionary formatterProperties = new Hashtable();
            formatterProperties[@"includeVersions"] = false;

            var serverFormatterSinkProvider = new BinaryServerFormatterSinkProvider(formatterProperties, null);
            serverFormatterSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
            return serverFormatterSinkProvider;
        }
Exemplo n.º 29
0
 public static void CreateChannel(String type, int port)
 {
     BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
     provider.TypeFilterLevel = TypeFilterLevel.Full;
     IDictionary properties = new Hashtable();
     properties["port"] = port;
     properties["name"] = String.Format("{0} Channel", type);
     channel = new TcpChannel(properties, null, provider);
 }
Exemplo n.º 30
0
		public static void Init(int port)
		{
			BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
			serverProv.TypeFilterLevel = TypeFilterLevel.Full;
			BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
			IDictionary props = new Hashtable();
			props["port"] = port;
			TcpChannel tcp_channel = new TcpChannel(props, clientProv, serverProv);
			ChannelServices.RegisterChannel(tcp_channel, false);
		}