public TCPManager(string ipAddress) { IPAddress = ipAddress; // Create message receiver receiving 'MyRequest' and receiving 'MyResponse'. aReceiverFactory = new DuplexTypedMessagesFactory(); myReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver <String, String>(); // Subscribe to handle messages. myReceiver.MessageReceived += OnMessageReceived; // Create TCP messaging. // Note: 192.168.0.100 is the IP from the wireless router (no internet) // and 8800 is the socket. aMessaging = new TcpMessagingSystemFactory(); anInputChannel = aMessaging.CreateDuplexInputChannel(IPAddress); // Attach the input channel and start to listen to messages. try { myReceiver.AttachDuplexInputChannel(anInputChannel); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void PortAvailability() { IDuplexInputChannel anInputChannel1 = MessagingSystemFactory.CreateDuplexInputChannel("tcp://[::1]:8044/"); IDuplexInputChannel anInputChannel2 = MessagingSystemFactory.CreateDuplexInputChannel("tcp://127.0.0.1:8044/"); try { anInputChannel1.StartListening(); anInputChannel2.StartListening(); Console.WriteLine("Available IP addresses:"); string[] anAvailableIpAddresses = TcpMessagingSystemFactory.GetAvailableIpAddresses(); foreach (string anIpAddress in anAvailableIpAddresses) { Console.WriteLine(anIpAddress); } bool aResult = TcpMessagingSystemFactory.IsPortAvailableForTcpListening("tcp://[::1]:8044/"); Assert.IsFalse(aResult); aResult = TcpMessagingSystemFactory.IsPortAvailableForTcpListening("tcp://0.0.0.0:8044/"); Assert.IsTrue(aResult); } finally { anInputChannel1.StopListening(); anInputChannel2.StopListening(); } }
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 }
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 void AttachDuplexInputChannel(IDuplexInputChannel duplexInputChannel) { using (EneterTrace.Entering()) { using (ThreadLock.Lock(myDuplexInputChannels)) { Attach(duplexInputChannel); try { duplexInputChannel.StartListening(); } catch (Exception err) { // Try to clean after the failure try { DetachDuplexInputChannel(duplexInputChannel.ChannelId); } catch { } string aMessage = TracedObject + "failed to start listening for '" + duplexInputChannel.ChannelId + "'."; EneterTrace.Error(aMessage, err); throw; } } } }
public void AttachDuplexInputChannel(IDuplexInputChannel duplexInputChannel) { using (EneterTrace.Entering()) { myReceiver.AttachDuplexInputChannel(duplexInputChannel); } }
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(); }
private void Attach(IDuplexInputChannel duplexInputChannel) { using (EneterTrace.Entering()) { using (ThreadLock.Lock(myDuplexInputChannels)) { if (duplexInputChannel == null) { string aMessage = TracedObject + "failed to attach duplex input channel because the input parameter 'duplexInputChannel' is null."; EneterTrace.Error(aMessage); throw new ArgumentNullException(aMessage); } if (string.IsNullOrEmpty(duplexInputChannel.ChannelId)) { string aMessage = TracedObject + "failed to attach duplex input channel because the input parameter 'duplexInputChannel' has empty or null channel id."; EneterTrace.Error(aMessage); throw new ArgumentException(aMessage); } if (myDuplexInputChannels.ContainsKey(duplexInputChannel.ChannelId)) { string anErrorMessage = TracedObject + "failed to attach duplex input channel because the channel with id '" + duplexInputChannel.ChannelId + "' is already attached."; EneterTrace.Error(anErrorMessage); throw new InvalidOperationException(anErrorMessage); } myDuplexInputChannels[duplexInputChannel.ChannelId] = new TDuplexInputChannel(duplexInputChannel); duplexInputChannel.MessageReceived += OnMessageReceived; } } }
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 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 SharedMemoryMessagingSystemFactory(); IDuplexInputChannel aMessageBusServiceInputChannel = anUnderlyingMessaging.CreateDuplexInputChannel("MyServicesAddress"); IDuplexInputChannel aMessageBusClientInputChannel = anUnderlyingMessaging.CreateDuplexInputChannel("MyClientsAddress"); myMessageBus = new MessageBusFactory().CreateMessageBus(); myMessageBus.AttachDuplexInputChannels(aMessageBusServiceInputChannel, aMessageBusClientInputChannel); MessagingSystemFactory = new MessageBusMessagingFactory("MyServicesAddress", "MyClientsAddress", anUnderlyingMessaging) { ConnectTimeout = TimeSpan.FromMilliseconds(3000) }; // Address of the service in the message bus. ChannelId = "Service1_Address"; }
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); }
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; } // 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(); }
public void ClientReceiveTimeout() { IMessagingSystemFactory aMessaging = new WebSocketMessagingSystemFactory() { ReceiveTimeout = TimeSpan.FromMilliseconds(1000) }; IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("ws://127.0.0.1:8046/"); IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("ws://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(); } }
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(); }
private void Attach(IDuplexInputChannel duplexInputChannel) { using (EneterTrace.Entering()) { using (ThreadLock.Lock(myDuplexInputChannelManipulatorLock)) { if (duplexInputChannel == null) { string aMessage = TracedObject + "failed to attach duplex input channel because the input parameter 'duplexInputChannel' is null."; EneterTrace.Error(aMessage); throw new ArgumentNullException(aMessage); } if (string.IsNullOrEmpty(duplexInputChannel.ChannelId)) { string aMessage = TracedObject + "failed to attach duplex input channel because the input parameter 'duplexInputChannel' has empty or null channel id."; EneterTrace.Error(aMessage); throw new ArgumentException(aMessage); } if (IsDuplexInputChannelAttached) { string aMessage = TracedObject + "failed to attach duplex input channel '" + duplexInputChannel.ChannelId + "' because the channel is already attached."; EneterTrace.Error(aMessage); throw new InvalidOperationException(aMessage); } AttachedDuplexInputChannel = duplexInputChannel; AttachedDuplexInputChannel.MessageReceived += OnRequestMessageReceived; AttachedDuplexInputChannel.ResponseReceiverConnected += OnResponseReceiverConnected; AttachedDuplexInputChannel.ResponseReceiverDisconnected += OnResponseReceiverDisconnected; } } }
public virtual void AttachDuplexInputChannel(IDuplexInputChannel duplexInputChannel) { using (EneterTrace.Entering()) { using (ThreadLock.Lock(myDuplexInputChannelManipulatorLock)) { Attach(duplexInputChannel); try { AttachedDuplexInputChannel.StartListening(); } catch (Exception err) { try { DetachDuplexInputChannel(); } catch { // Ignore exception in exception. } EneterTrace.Error(TracedObject + ErrorHandler.FailedToStartListening, err); throw; } } } }
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(); }
/// <summary> /// Creates the input channel which can receive messages from the output channel and send response messages. /// </summary> /// <remarks> /// If the connection with the duplex output channel is not established, it puts sent response messages to the buffer. /// Then, when the duplex input channel is connected, the response messages are sent. /// If the duplex output channel does not connect within the specified maximum offline time, the event /// <see cref="IDuplexInputChannel.ResponseReceiverDisconnected"/> is invoked and response messages are deleted from the buffer. /// </remarks> /// <param name="channelId">channel id, the syntax of the channel id must comply to underlying messaging</param> /// <returns>buffered duplex input channel</returns> public IBufferedDuplexInputChannel CreateDuplexInputChannel(string channelId) { using (EneterTrace.Entering()) { IDuplexInputChannel anUnderlyingDuplexInputChannel = myUnderlyingMessaging.CreateDuplexInputChannel(channelId); return(new BufferedDuplexInputChannel(anUnderlyingDuplexInputChannel, myMaxOfflineTime)); } }
public void AttachDuplexInputChannel(IDuplexInputChannel duplexInputChannel) { lock (this) { Attach(duplexInputChannel); DuplexInputChannel.StartListening(); } }
public TClient(IDuplexInputChannel inputChannel, string inputResponseReceiverId) { using (EneterTrace.Entering()) { myInputChannel = inputChannel; myInputResponseReceiverId = inputResponseReceiverId; } }
public void BroadcastFromClientToAllServices() { UdpMessagingSystemFactory anOutputChannelMessaging = new UdpMessagingSystemFactory(new EasyProtocolFormatter()) { UnicastCommunication = false, AllowSendingBroadcasts = true }; UdpMessagingSystemFactory anInputChannelMessaging = new UdpMessagingSystemFactory(new EasyProtocolFormatter()) { UnicastCommunication = false, ReuseAddress = true }; ManualResetEvent aMessage1Received = new ManualResetEvent(false); string aReceivedMessage1 = null; IDuplexInputChannel anInputChannel1 = anInputChannelMessaging.CreateDuplexInputChannel("udp://127.0.0.1:8095/"); anInputChannel1.MessageReceived += (x, y) => { aReceivedMessage1 = (string)y.Message; aMessage1Received.Set(); }; ManualResetEvent aMessage2Received = new ManualResetEvent(false); string aReceivedMessage2 = null; IDuplexInputChannel anInputChannel2 = anInputChannelMessaging.CreateDuplexInputChannel("udp://127.0.0.1:8095/"); anInputChannel2.MessageReceived += (x, y) => { aReceivedMessage2 = (string)y.Message; aMessage2Received.Set(); }; IDuplexOutputChannel anOutputChannel = anOutputChannelMessaging.CreateDuplexOutputChannel("udp://255.255.255.255:8095/", "udp://127.0.0.1"); try { anInputChannel1.StartListening(); anInputChannel2.StartListening(); anOutputChannel.OpenConnection(); anOutputChannel.SendMessage("Hello"); aMessage1Received.WaitIfNotDebugging(1000); aMessage2Received.WaitIfNotDebugging(1000); } finally { anOutputChannel.CloseConnection(); anInputChannel1.StopListening(); anInputChannel2.StopListening(); } Assert.AreEqual("Hello", aReceivedMessage1); Assert.AreEqual("Hello", aReceivedMessage2); }
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(); }
/// <summary> /// Creates the input channel which can receive messages from the output channel and send response messages. /// </summary> /// <remarks> /// In addition it expects receiving ping messages from each connected client within a specified time and sends /// ping messages to each connected client in a specified frequency. /// </remarks> /// <param name="channelId">input channel address. It must comply to underlying messaging</param> /// <returns>monitoring duplex input channel</returns> public IDuplexInputChannel CreateDuplexInputChannel(string channelId) { using (EneterTrace.Entering()) { IDuplexInputChannel anUnderlyingChannel = myUnderlyingMessaging.CreateDuplexInputChannel(channelId); IThreadDispatcher aThreadDispatcher = InputChannelThreading.GetDispatcher(); return(new MonitoredDuplexInputChannel(anUnderlyingChannel, Serializer, (int)PingFrequency.TotalMilliseconds, (int)ReceiveTimeout.TotalMilliseconds, aThreadDispatcher)); } }
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 BufferedDuplexInputChannel(IDuplexInputChannel underlyingDuplexInputChannel, TimeSpan maxOfflineTime) { using (EneterTrace.Entering()) { myInputChannel = underlyingDuplexInputChannel; myMaxOfflineTime = maxOfflineTime; myMaxOfflineChecker = new Timer(OnMaxOfflineTimeCheckTick, null, -1, -1); } }
public void MulticastFromServiceToClients() { UdpMessagingSystemFactory aMessaging = new UdpMessagingSystemFactory(new EasyProtocolFormatter()) { UnicastCommunication = false, ReuseAddress = true, MulticastGroupToReceive = "234.1.2.3", MulticastLoopback = true }; ManualResetEvent aMessage1Received = new ManualResetEvent(false); string aReceivedMessage1 = null; IDuplexOutputChannel anOutputChannel1 = aMessaging.CreateDuplexOutputChannel("udp://127.0.0.1:8090/", "udp://127.0.0.1:8092/"); anOutputChannel1.ResponseMessageReceived += (x, y) => { aReceivedMessage1 = (string)y.Message; aMessage1Received.Set(); }; ManualResetEvent aMessage2Received = new ManualResetEvent(false); string aReceivedMessage2 = null; IDuplexOutputChannel anOutputChannel2 = aMessaging.CreateDuplexOutputChannel("udp://127.0.0.1:8090/", "udp://127.0.0.1:8092/"); anOutputChannel2.ResponseMessageReceived += (x, y) => { aReceivedMessage2 = (string)y.Message; aMessage2Received.Set(); }; IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("udp://127.0.0.1:8090/"); try { anInputChannel.StartListening(); anOutputChannel1.OpenConnection(); anOutputChannel2.OpenConnection(); anInputChannel.SendResponseMessage("udp://234.1.2.3:8092/", "Hello"); aMessage1Received.WaitIfNotDebugging(1000); aMessage2Received.WaitIfNotDebugging(1000); } finally { anInputChannel.StopListening(); anOutputChannel1.CloseConnection(); anOutputChannel2.CloseConnection(); } Assert.AreEqual("Hello", aReceivedMessage1); Assert.AreEqual("Hello", aReceivedMessage2); }
public TBufferedResponseReceiver(string responseReceiverId, IDuplexInputChannel duplexInputChannel) { ResponseReceiverId = responseReceiverId; // Note: at the time of instantiation the client address does not have to be known. // E.g. if sending response to a not yet connected response receiver. // Therefore it will be set explicitly. ClientAddress = ""; myDuplexInputChannel = duplexInputChannel; IsOnline = false; }
public void AttachInputChannel() { anInputChannel = UnderlyingMessaging.CreateDuplexInputChannel(Self); switch (MessagesFactoryType) { case YZXMessagesFactoryType.Duplex: DReceiver.AttachDuplexInputChannel(anInputChannel); break; } }
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"); }