public void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); // Generate random number for the port. int aPort1 = RandomPortGenerator.GenerateInt(); int aPort2 = aPort1 + 10; IMessagingSystemFactory anUnderlyingMessaging = new TcpMessagingSystemFactory(new EasyProtocolFormatter()); IDuplexInputChannel aMessageBusServiceInputChannel = anUnderlyingMessaging.CreateDuplexInputChannel("tcp://[::1]:" + aPort1 + "/"); IDuplexInputChannel aMessageBusClientInputChannel = anUnderlyingMessaging.CreateDuplexInputChannel("tcp://[::1]:" + aPort2 + "/"); myMessageBus = new MessageBusFactory().CreateMessageBus(); myMessageBus.AttachDuplexInputChannels(aMessageBusServiceInputChannel, aMessageBusClientInputChannel); MessagingSystemFactory = new MessageBusMessagingFactory("tcp://[::1]:" + aPort1 + "/", "tcp://[::1]:" + aPort2 + "/", anUnderlyingMessaging) { ConnectTimeout = TimeSpan.FromMilliseconds(3000) }; // Address of the service in the message bus. ChannelId = "Service1_Address"; CompareResponseReceiverId = false; }
public Form1() { aFactory = new RpcFactory(); aService = aFactory.CreateSingleInstanceService <IMyService>(new MyService()); // Use TCP for the communication. // You also can use other protocols e.g. WebSockets. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://192.168.1.102:8041/"); // Attach the input channel to the RpcService and start listening. aService.AttachDuplexInputChannel(anInputChannel); //IS THIS SERVICE MULTITHREADED ? InitializeComponent(); button2.Enabled = false; button3.Enabled = true; var materialSkinManager = MaterialSkinManager.Instance; materialSkinManager.AddFormToManage(this); materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT; materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE); formContext = this; //don't run more than 1 instances of this form }
private void StartServiceBtn_Click(object sender, EventArgs e) { if (myReceiver.IsDuplexInputChannelAttached) { // The channel is already attached so nothing to do. return; } // Use TCP communication IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory() { // Set to receive messages in the main UI thread. // Note: if this is not set then methods OnMessageReceived, OnClientConnected // and OnClientDisconnected would not be called from main UI thread // but from a listener thread. MaxAmountOfConnections = 5, InputChannelThreading = new WinFormsDispatching(this) }; // Create input channel. IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8060/"); // Attach the input channel and be able to receive messages // and send back response messages. myReceiver.AttachDuplexInputChannel(anInputChannel); ServiceStatusLabel.Text = "Service Running"; }
static void Main(string[] args) { string aServiceAddress = GetMyAddress(); if (aServiceAddress == "") { Console.WriteLine("The service could not start because all possible ports are occupied"); return; } // TCP message protocol for receiving requests IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel(aServiceAddress); IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory(); IDuplexTypedMessageReceiver <double, Range> aReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver <double, Range>(); aReceiver.MessageReceived += OnMessageReceived; aReceiver.AttachDuplexInputChannel(anInputChannel); Console.WriteLine("Root Square Calculator listening to " + aServiceAddress + " is running.\r\n Press ENTER to stop."); Console.ReadLine(); aReceiver.DetachDuplexInputChannel(); }
public void ClientReceiveTimeout() { IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory() { ReceiveTimeout = TimeSpan.FromMilliseconds(1000) }; IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8046/"); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8046/"); try { ManualResetEvent aConnectionClosed = new ManualResetEvent(false); anOutputChannel.ConnectionClosed += (x, y) => { EneterTrace.Info("Connection closed."); aConnectionClosed.Set(); }; anInputChannel.StartListening(); anOutputChannel.OpenConnection(); EneterTrace.Info("Connection opened."); // According to set receive timeout the client should get disconnected within 1 second. //aConnectionClosed.WaitOne(); Assert.IsTrue(aConnectionClosed.WaitOne(3000)); } finally { anOutputChannel.CloseConnection(); anInputChannel.StopListening(); } }
public void StartServer() { // Start the policy server to be able to communicate with silverlight. myPolicyServer.StartPolicyServer(); // Create duplex message receiver. // It can receive messages and also send back response messages. IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory(); CommandReceiver = aStringMessagesFactory.CreateDuplexStringMessageReceiver(); CommandReceiver.ResponseReceiverConnected += ClientConnected; CommandReceiver.ResponseReceiverDisconnected += ClientDisconnected; CommandReceiver.RequestReceived += MessageReceived; // Create TCP based messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel aDuplexInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:4502"); // Attach the duplex input channel to the message receiver and start listening. // Note: Duplex input channel can receive messages but also send messages back. CommandReceiver.AttachDuplexInputChannel(aDuplexInputChannel); Logger.Info("Server started"); StartWorker4504Server(); }
public void Start() { if (myReceiver.IsDuplexInputChannelAttached) { // The channel is already attached so nothing to do. return; } // Use TCP communication IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory() { // Set to receive messages in the main UI thread. // Note: if this is not set then methods OnMessageReceived, OnClientConnected // and OnClientDisconnected would not be called from main UI thread // but from a listener thread. MaxAmountOfConnections = 5, //InputChannelThreading = new AsyncDispatching(); //TODO // InputChannelThreading = new WinFormsDispatching(this) }; // Create input channel. IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel(ServerIp); // Attach the input channel and be able to receive messages // and send back response messages. myReceiver.AttachDuplexInputChannel(anInputChannel); }
static void Main(string[] args) { // Create ProtoBuf serializer. ISerializer aSerializer = new ProtoBufSerializer(); // Create message receiver. IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory(aSerializer); IDuplexTypedMessageReceiver<ResponseMessage, RequestMessage> aReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver<ResponseMessage, RequestMessage>(); // Subscribe to process request messages. aReceiver.MessageReceived += OnMessageReceived; // Use TCP for the communication. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:4502/"); // Attach the input channel to the receiver and start listening. aReceiver.AttachDuplexInputChannel(anInputChannel); Console.WriteLine("The calculator service is running. Press ENTER to stop."); Console.ReadLine(); // Detach the input channel to stop listening. aReceiver.DetachDuplexInputChannel(); }
static void Main(string[] args) { string aServiceAddress = GetMyAddress(); if (aServiceAddress == "") { Console.WriteLine("The service could not start because all possible ports are occupied."); return; } // Create TCP messaging for receiving requests. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel(aServiceAddress); // Create typed message receiver to receive requests. // It receives request messages of type Range and sends back // response messages of type double. IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory(); IDuplexTypedMessageReceiver <double, Range> aReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver <double, Range>(); // Subscribre to messages. aReceiver.MessageReceived += OnMessageReceived; // Attach the input channel and start listening. aReceiver.AttachDuplexInputChannel(anInputChannel); Console.WriteLine("Root Square Calculator listening to " + aServiceAddress + " is running.\r\n Press ENTER to stop."); Console.ReadLine(); // Detach the input channel and stop listening. aReceiver.DetachDuplexInputChannel(); }
static void Main(string[] args) { // Create TCP messaging for the communication with the client // and with services performing requests. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); // Create load balancer. ILoadBalancerFactory aLoadBalancerFactory = new RoundRobinBalancerFactory(aMessaging); ILoadBalancer aLoadBalancer = aLoadBalancerFactory.CreateLoadBalancer(); // Addresses of available services. string[] anAvailableServices = { "tcp://127.0.0.1:8071/", "tcp://127.0.0.1:8072/", "tcp://127.0.0.1:8073/" }; // Add IP addresses of services to the load balancer. foreach (string anIpAddress in anAvailableServices) { aLoadBalancer.AddDuplexOutputChannel(anIpAddress); } // Create input channel that will listen to requests from clients. IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8060/"); // Attach the input channel to the load balancer and start listening. aLoadBalancer.AttachDuplexInputChannel(anInputChannel); Console.WriteLine("Load Balancer is running.\r\nPress ENTER to stop."); Console.ReadLine(); // Stop lisening. aLoadBalancer.DetachDuplexInputChannel(); }
static void Main(string[] args) { // Instantiate Protocol Buffer based serializer. ISerializer aSerializer = new ProtoBufSerializer(); // Create message receiver receiving 'MyRequest' and receiving 'MyResponse'. // The receiver will use Protocol Buffers to serialize/deserialize messages. IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory(aSerializer); myReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver<MyResponse, MyRequest>(); // Subscribe to handle messages. myReceiver.MessageReceived += OnMessageReceived; // Create TCP messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8060/"); // Attach the input channel and start to listen to messages. myReceiver.AttachDuplexInputChannel(anInputChannel); Console.WriteLine("The service is running. To stop press enter."); Console.ReadLine(); // Detach the input channel and stop listening. // It releases the thread listening to messages. myReceiver.DetachDuplexInputChannel(); }
public static void run() { // Create message receiver receiving 'MyRequest' and receiving 'MyResponse'. IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory(); myReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver <MyResponse, MyRequest>(); // Subscribe to handle messages. myReceiver.MessageReceived += OnMessageReceived; // Create TCP messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://192.168.43.167:8067/"); //= aMessaging.CreateDuplexInputChannel("tcp://192.168.173.1:8060/"); // Attach the input channel and start to listen to messages. myReceiver.AttachDuplexInputChannel(anInputChannel); Console.WriteLine("The service is running. To stop press enter."); Console.ReadLine(); // Detach the input channel and stop listening. // It releases the thread listening to messages. myReceiver.DetachDuplexInputChannel(); }
public void Start() { // We use TCP based messaging. IMessagingSystemFactory aServiceMessagingSystem = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aServiceMessagingSystem.CreateDuplexInputChannel("tcp://127.0.0.1:8091/"); // Attach the input channel to the unwrapper and start to listening. myDuplexChannelUnwrapper.AttachDuplexInputChannel(anInputChannel); }
static void Main(string[] args) { IMessagingSystemFactory messagingSystemFactoryTCP = new TcpMessagingSystemFactory(); DuplexStringMessagesFactory aReceiverFactory = new DuplexStringMessagesFactory(); myStringReceiver = aReceiverFactory.CreateDuplexStringMessageReceiver(); // Subscribe to get notified when a client connects, disconnects // or sends a message. myStringReceiver.RequestReceived += OnMessageReceived; myStringReceiver.ResponseReceiverConnected += OnConnect; IMessagingSystemFactory stringMessaging = new TcpMessagingSystemFactory() { // Set to receive messages in the main UI thread. // Note: if this is not set then methods OnMessageReceived, OnClientConnected // and OnClientDisconnected would not be called from main UI thread // but from a listener thread. MaxAmountOfConnections = 5 }; // Create input channel. IDuplexInputChannel aInputChannel = stringMessaging.CreateDuplexInputChannel("tcp://192.168.1.5:8061/"); // Attach the input channel and be able to receive messages // and send back response messages. myStringReceiver.AttachDuplexInputChannel(aInputChannel); IMessagingSystemFactory aTcpMessaging = new TcpMessagingSystemFactory(); // Use authenticated connection. IMessagingSystemFactory aMessaging = new AuthenticatedMessagingFactory(aTcpMessaging, GetHandshakeMessage, Authenticate); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://192.168.1.5:8060/"); // Use simple text messages. IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory(); myReceiver = aStringMessagesFactory.CreateDuplexStringMessageReceiver(); myReceiver.RequestReceived += OnRequestReceived; // Attach input channel and start listening. // Note: the authentication sequence will be performed when // a client connects the service. myReceiver.AttachDuplexInputChannel(anInputChannel); Console.WriteLine("Service is running. Press Enter to stop."); Console.ReadLine(); // Detach input channel and stop listening. // Note: tis will release the listening thread. myReceiver.DetachDuplexInputChannel(); }
public void StartReceiving() { // Create messaging based on TCP. IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory(); IDuplexInputChannel anDuplexInputChannel = aMessagingSystemFactory.CreateDuplexInputChannel("tcp://127.0.0.1:8094/"); // Attach the input channel and be able to receive messages and send back responses. myMessageReceiver.AttachDuplexInputChannel(anDuplexInputChannel); }
public void Setup() { string aPort = RandomPortGenerator.Generate(); string anAddress = "tcp://127.0.0.1:" + aPort + "/"; IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); InputChannel = aMessaging.CreateDuplexInputChannel(anAddress); OutputChannel = aMessaging.CreateDuplexOutputChannel(anAddress); DuplexTypedMessagesFactory = new DuplexTypedMessagesFactory(); }
public void StartWorker4504Server() { // Create TCP based messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); Worker4504InputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:4504"); Worker4504InputChannel.MessageReceived += Worker4504InputChannel_MessageReceived; Worker4504InputChannel.ResponseReceiverConnected += ClientConnected; Worker4504InputChannel.ResponseReceiverDisconnected += ClientDisconnected; //Worker4504InputChannel.ResponseReceiverConnected += Worker4504InputChannel_ResponseReceiverConnected; //Worker4504InputChannel.ResponseReceiverDisconnected += Worker4504InputChannel_ResponseReceiverDisconnected; Worker4504InputChannel.StartListening(); Logger.Info("Worker server 4504 started"); }
public TalkFlow() { var talk = new Talk(); IRpcFactory factory = new RpcFactory(); IRpcService <ITalk> service = factory.CreateSingleInstanceService <ITalk>(talk); IMessagingSystemFactory messaging = new TcpMessagingSystemFactory(); IDuplexInputChannel inputChannel = messaging.CreateDuplexInputChannel("tcp://127.0.0.1:8045/"); service.AttachDuplexInputChannel(inputChannel); Console.WriteLine("Service started. Press ENTER to stop."); Console.ReadLine(); service.DetachDuplexInputChannel(); }
static void Main(string[] args) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // TCP messaging protocol for communication with the master node IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); // Create load scheduler ILoadBalancerFactory aLoadBalancerFactory = new RoundRobinBalancerFactory(aMessaging); ILoadBalancer aLoadBalancer = aLoadBalancerFactory.CreateLoadBalancer(); // Addresses of cluster compute nodes string[] anAvailableServices = { "tcp://127.0.0.1:8071/", "tcp://127.0.0.1:8072/", "tcp://127.0.0.1:8073/", "tcp://127.0.0.1:8074/", "tcp://127.0.0.1:8075/" }; foreach (string anIpAddress in anAvailableServices) { aLoadBalancer.AddDuplexOutputChannel(anIpAddress); } // Create input channel listening to master node IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8060/"); aLoadBalancer.AttachDuplexInputChannel(anInputChannel); stopWatch.Stop(); long duration = stopWatch.ElapsedMilliseconds; Console.WriteLine("-------------------------------\n"); Console.WriteLine("Ready Time : {0}ms", duration); Console.WriteLine("Load Scheduler is running.\r\nPress ENTER to stop."); stopWatch.Start(); Console.ReadLine(); stopWatch.Stop(); duration = stopWatch.ElapsedMilliseconds; Console.WriteLine("Completion Time : {0}ms", duration); Console.ReadLine(); aLoadBalancer.DetachDuplexInputChannel(); }
public void MaxAmountOfConnections() { IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory() { MaxAmountOfConnections = 2 }; IDuplexOutputChannel anOutputChannel1 = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8049/"); IDuplexOutputChannel anOutputChannel2 = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8049/"); IDuplexOutputChannel anOutputChannel3 = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8049/"); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8049/"); try { ManualResetEvent aConnectionClosed = new ManualResetEvent(false); anOutputChannel3.ConnectionClosed += (x, y) => { EneterTrace.Info("Connection closed."); aConnectionClosed.Set(); }; anInputChannel.StartListening(); anOutputChannel1.OpenConnection(); anOutputChannel2.OpenConnection(); anOutputChannel3.OpenConnection(); if (!aConnectionClosed.WaitOne(1000)) { Assert.Fail("Third connection was not closed."); } Assert.IsTrue(anOutputChannel1.IsConnected); Assert.IsTrue(anOutputChannel2.IsConnected); Assert.IsFalse(anOutputChannel3.IsConnected); } finally { anOutputChannel1.CloseConnection(); anOutputChannel2.CloseConnection(); anOutputChannel3.CloseConnection(); anInputChannel.StopListening(); } }
// Connect public void Connect(string channelID) { // Create message receiver receiving 'MyRequest' and receiving 'MyResponse'. IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory(); myReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver <MyResponse, MyRequest>(); // Subscribe to handle messages. myReceiver.MessageReceived += OnMessageReceived; // Create TCP messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel(channelID); // Attach the input channel and start to listen to messages. myReceiver.AttachDuplexInputChannel(anInputChannel); isConnected = true; }
public MainWindow() { InitializeComponent(); Loaded += MainWindowLoaded; SizeChanged += MainWindowSizeChanged; var target = LogManager.Configuration.AllTargets .Where(x => x.Name == TargetName) .Single() as MemoryTargetEx; if (target != null) target.Messages.Subscribe(msg => _messages.Add(msg)); // Start the policy server to be able to communicate with silverlight. // Note: Before Silverlight open the communication it asks the policy // server for the policy xml. // If the policy server is not present or the content of the // policy xml does not allow the communication the communication // is not open. myPolicyServer = new TcpPolicyServer(); myPolicyServer.StartPolicyServer(); // Create duplex message receiver. // It can receive messages and also send back response messages. IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory(); myMessageReceiver = aStringMessagesFactory.CreateDuplexStringMessageReceiver(); myMessageReceiver.ResponseReceiverConnected += ClientConnected; myMessageReceiver.ResponseReceiverDisconnected += ClientDisconnected; myMessageReceiver.RequestReceived += MessageReceived; // Create TCP based messaging. // Note: TCP in Silverlight can use only ports 4502 - 4532. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel aDuplexInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:4502/"); // Attach the duplex input channel to the message receiver and start listening. // Note: Duplex input channel can receive messages but also send messages back. myMessageReceiver.AttachDuplexInputChannel(aDuplexInputChannel); }
static void Main(string[] args) { // Create ProtoBuf serializer. ISerializer aSerializer = new ProtoBufSerializer(); // Create the broker. IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory(aSerializer); IDuplexBroker aBroker = aBrokerFactory.CreateBroker(); // Create the Input channel receiving messages via Tcp. // Note: You can also choose NamedPipes or Http. // (if you choose http, do not forget to execute it with sufficient user rights) IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexInputChannel aBrokerInputChannel = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:7091/"); aBroker.AttachDuplexInputChannel(aBrokerInputChannel); // Attach the input channel to the broker and start listening. Console.WriteLine("The broker application is running. Press ENTER to stop."); Console.ReadLine(); aBroker.DetachDuplexInputChannel(); }
private void SMSIM_Load(object sender, EventArgs e) { IDuplexStringMessagesFactory aReceiverFactory = new DuplexStringMessagesFactory(); receiver = aReceiverFactory.CreateDuplexStringMessageReceiver(); receiver.RequestReceived += handleRequest; IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); String localIP = LocalIPAddress(); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://" + localIP + ":8060/"); receiver.AttachDuplexInputChannel(anInputChannel); if (receiver.IsDuplexInputChannelAttached) ipAddress.Text = localIP; this.ActiveControl = label1; System.Timers.Timer pingTimer = new System.Timers.Timer(); pingTimer.Elapsed += new ElapsedEventHandler(pingTimeout); pingTimer.Interval = 1000 * 30; pingTimer.Enabled = true; }