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(); } }
/// <summary> /// Returns IP addresses assigned to the device which can be used for listening. /// </summary> /// <returns>array of available addresses</returns> public static string[] GetAvailableIpAddresses() { using (EneterTrace.Entering()) { return(TcpMessagingSystemFactory.GetAvailableIpAddresses()); } }
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(); } }
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 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; }
private void OpenConnectionBtn_Click(object sender, EventArgs e) { if (!mySender.IsDuplexOutputChannelAttached) { // The output channel is not attached yet. // So attach the output channel and be able to send // request messagas and receive response messages. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory() { // Set to receive messages in the main UI thread. // Note: if this is not set then methods OnResponseReceived and // OnConnectionClosed would not be called from main UI thread // but from a listener thread. OutputChannelThreading = new WinFormsDispatching(this) }; IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8033/"); mySender.AttachDuplexOutputChannel(anOutputChannel); ConnectionStatusLabel.Text = "Client Connected"; } else if (!mySender.AttachedDuplexOutputChannel.IsConnected) { // The output channel is attached but the client got disconnected. // So jut reopen the connection. mySender.AttachedDuplexOutputChannel.OpenConnection(); ConnectionStatusLabel.Text = "Client Connected"; } }
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"); //EneterTrace.StartProfiler(); // Generate random number for the port. string aPort = RandomPortGenerator.Generate(); TcpMessagingSystemFactory anUnderlyingMessaging = new TcpMessagingSystemFactory(); //ChannelId = "tcp://127.0.0.1:" + aPort + "/"; ChannelId = "tcp://[::1]:" + aPort + "/"; MessagingSystemFactory = new AuthenticatedMessagingFactory(anUnderlyingMessaging, GetLoginMessage, GetHandshakeResponseMessage, GetHandshakeMessage, VerifyHandshakeResponseMessage, HandleAuthenticationCancelled) { AuthenticationTimeout = TimeSpan.FromMilliseconds(2000) }; myHandshakeSerializer = new AesSerializer("Password123"); }
public new void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); //EneterTrace.StartProfiler(); ResourceManager aResourceManager = new ResourceManager("Eneter.MessagingUnitTests.Properties.Resources", typeof(Resources).Assembly); // Get the server certificate from the resources. byte[] aServerCertBytes = (byte[])aResourceManager.GetObject("UTestServer"); X509Certificate2 aServerCertificate = new X509Certificate2(aServerCertBytes); //X509Certificate2 aServerCertificate = new X509Certificate2("d://UTestServer.pfx"); // Get the client certificate from the resources. byte[] aClientCertBytes = (byte[])aResourceManager.GetObject("UTestClient"); X509Certificate aClientCertificate = new X509Certificate(aClientCertBytes); X509CertificateCollection aClientCertList = new X509CertificateCollection(); aClientCertList.Add(aClientCertificate); MessagingSystemFactory = new TcpMessagingSystemFactory() { ClientSecurityStreamFactory = new ClientSslFactory("127.0.0.1", null, (x, y, z, q) => { // Confirm the certificate from the service is OK. return(true); }, null), ServerSecurityStreamFactory = new ServerSslFactory(aServerCertificate) }; ChannelId = "tcp://127.0.0.1:8091/"; }
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 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) { // 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; } // 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 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(); }
private bool InitializeWorkerConnection() { // Create TCP messaging IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); Worker4504OutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4504/"); // Subscribe to response messages. Worker4504OutputChannel.ConnectionClosed += Worker4504OutputChannel_ConnectionClosed; Worker4504OutputChannel.ConnectionOpened += Worker4504OutputChannel_ConnectionOpened; Worker4504OutputChannel.ResponseMessageReceived += Worker4504OutputChannel_ResponseMessageReceived; // Open connection and be able to send messages and receive response messages. Worker4504OutputChannel.OpenConnection(); Log("Channel id : " + Worker4504OutputChannel.ChannelId); // Send a message. byte[] data = new byte[1048576]; // initialize 1MB data //byte[] data = new byte[10]; // initialize 1MB data Random random = new Random(); random.NextBytes(data); Worker4504OutputChannel.SendMessage(data); Log("Sent data length : " + data.Length); // Close connection. //Worker4504OutputChannel.CloseConnection(); return(true); }
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) { 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 Main() { try { InitializeComponent(); ProcessFile(); WriteFile(); MessageBox.Show("Done!"); return; _mMouseHookManager = new MouseHookListener(new GlobalHooker()) {Enabled = true}; _mMouseHookManager.MouseUp += mMouseHookManager_MouseUp; ReadKeyFile(Properties.Settings.Default.KeyPath); IDuplexTypedMessagesFactory aSenderFactory = new DuplexTypedMessagesFactory(); _mySender = aSenderFactory.CreateDuplexTypedMessageSender<AppQA, MyResponse>(); IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + Properties.Settings.Default.IpAddress + ":8060/"); // Attach the input channel and start to listen to messages. _mySender.AttachDuplexOutputChannel(anOutputChannel); } catch (Exception exception) { WriteAnswer(Properties.Settings.Default.AnswerPath, exception.Message); } }
private bool Command_Initialize() { // Create duplex message sender. // It can send messages and also receive messages. IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory(); Command_MessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender(); Command_MessageSender.ResponseReceived += Command_ResponseReceived; // Create TCP based messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4502/"); // Attach the duplex output channel to the message sender // and be able to send messages and receive messages. try { Command_MessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel); } catch (Exception e) { Log(e.Message); } if (Command_MessageSender.IsDuplexOutputChannelAttached) { Log("Initialized connection."); return(true); } else { Log("Unable to initialize connection"); return(false); } }
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(); }
public Form1() { InitializeComponent(); // Create ProtoBuf serializer. mySerializer = new ProtoBufSerializer(); // Create the broker client that will receive notification messages. IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory(mySerializer); myBrokerClient = aBrokerFactory.CreateBrokerClient(); myBrokerClient.BrokerMessageReceived += OnNotificationMessageReceived; // Create the Tcp messaging for the communication with the publisher. // Note: For the interprocess communication you can use: Tcp, NamedPipes and Http. IMessagingSystemFactory aMessagingFactory = new TcpMessagingSystemFactory(); // Create duplex output channel for the communication with the publisher. // Note: The duplex output channel can send requests and receive responses. // In our case, the broker client will send requests to subscribe/unsubscribe // and receive notifications as response messages. myOutputChannel = aMessagingFactory.CreateDuplexOutputChannel("tcp://127.0.0.1:7091/"); // Attach the output channel to the broker client myBrokerClient.AttachDuplexOutputChannel(myOutputChannel); }
/// <summary> /// Constructs the messaging which communicates with Android via the USB cable. /// </summary> /// <remarks> /// The adb service typically starts automatically when you connect the Android device via the USB cable. /// </remarks> /// <param name="adbHostPort">Port where adb service is listening to commands. Default value is 5037.</param> /// <param name="protocolFormatter">Low level formatting used for encoding messages between channels. /// EneterProtocolFormatter() can be used by default. /// </param> public AndroidUsbCableMessagingFactory(int adbHostPort, IProtocolFormatter protocolFormatter) { using (EneterTrace.Entering()) { myAdbHostPort = adbHostPort; myUnderlyingTcpMessaging = new TcpMessagingSystemFactory(protocolFormatter); } }
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 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); }
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 new void Setup() { MessagingSystemFactory = new TcpMessagingSystemFactory() { ClientSecurityStreamFactory = new ClientNegotiateFactory(), ServerSecurityStreamFactory = new ServerNegotiateFactory() }; ChannelId = "tcp://127.0.0.1:8091/"; }
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 Notify_50000_TCP() { Random aRnd = new Random(); int aPort = aRnd.Next(8000, 9000); IMessagingSystemFactory aMessagingSystem = new TcpMessagingSystemFactory(); string aBrokerAddress = "tcp://127.0.0.1:" + aPort + "/"; ISerializer aSerializer = new BinarySerializer(); Notify(50000, aSerializer, aMessagingSystem, aBrokerAddress); }
public void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); ChannelId = "tcp://127.0.0.1:7080/"; UnderlyingMessaging = new TcpMessagingSystemFactory(); MessagingSystemFactory = new MonitoredMessagingFactory(UnderlyingMessaging, TimeSpan.FromMilliseconds(250), // e.g. if the communication is very intensive then it may take more time until the response is received. TimeSpan.FromMilliseconds(750)); }
public ChannelWrapper() { IMessagingSystemFactory anInternalMessaging = new SynchronousMessagingSystemFactory(); // The service receives messages via one channel (i.e. it listens on one address). // The incoming messages are unwrapped on the server side. // Therefore the client must use wrapper to send messages via one channel. IChannelWrapperFactory aChannelWrapperFactory = new ChannelWrapperFactory(); myDuplexChannelWrapper = aChannelWrapperFactory.CreateDuplexChannelWrapper(); // To connect message senders and the wrapper with duplex channels we can use the following helper class. IConnectionProviderFactory aConnectionProviderFactory = new ConnectionProviderFactory(); IConnectionProvider aConnectionProvider = aConnectionProviderFactory.CreateConnectionProvider(anInternalMessaging); // Factory to create message senders. // Sent messages will be serialized in Xml. IDuplexTypedMessagesFactory aCommandsFactory = new DuplexTypedMessagesFactory(); plusSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>(); plusSender.ResponseReceived += (s, e) => { Console.WriteLine("CW.V+: " + e.ResponseMessage.Value); }; // attach method handling the request aConnectionProvider.Connect(myDuplexChannelWrapper, plusSender, "plus"); // attach the input channel to get messages from unwrapper minusSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>(); minusSender.ResponseReceived += (s, e) => { Console.WriteLine("CW.V-: " + e.ResponseMessage.Value); }; // attach method handling the request aConnectionProvider.Connect(myDuplexChannelWrapper, minusSender, "minus"); // attach the input channel to get messages from unwrapper dotSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>(); dotSender.ResponseReceived += (s, e) => { Console.WriteLine("CW.V.: " + e.ResponseMessage.Value); }; // attach method handling the request aConnectionProvider.Connect(myDuplexChannelWrapper, dotSender, "dot"); // attach the input channel to get messages from unwrapper IMessagingSystemFactory aTcpMessagingSystem = new TcpMessagingSystemFactory(); // Create output channel to send requests to the service. IDuplexOutputChannel anOutputChannel = aTcpMessagingSystem.CreateDuplexOutputChannel("tcp://127.0.0.1:8091/"); // Attach the output channel to the wrapper - so that we are able to send messages // and receive response messages. // Note: The service has the coresponding unwrapper. myDuplexChannelWrapper.AttachDuplexOutputChannel(anOutputChannel); }
public void Notify_50000_TCP_Interop_BrokerSerializer() { Random aRnd = new Random(); int aPort = aRnd.Next(8000, 9000); IProtocolFormatter aProtocolFormatter = new EasyProtocolFormatter(); IMessagingSystemFactory aMessagingSystem = new TcpMessagingSystemFactory(aProtocolFormatter); string aBrokerAddress = "tcp://127.0.0.1:" + aPort + "/"; ISerializer aSerializer = new BrokerCustomSerializer(); Notify(50000, aSerializer, aMessagingSystem, aBrokerAddress); }
public void Setup() { IMessagingSystemFactory aMessagingSystem = new TcpMessagingSystemFactory(); // Generate random number for the port. Random aRnd = new Random(); int aPort = aRnd.Next(8000, 9000); string aChannelId = "tcp://127.0.0.1:" + aPort + "/"; ISerializer aSerializer = new BinarySerializer(); Setup(aMessagingSystem, aChannelId, aSerializer); }
public void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); //EneterTrace.StartProfiler(); // Generate random number for the port. string aPort = RandomPortGenerator.Generate(); MessagingSystemFactory = new TcpMessagingSystemFactory(); //ChannelId = "tcp://127.0.0.1:" + aPort + "/"; ChannelId = "tcp://[::1]:" + aPort + "/"; }
private void button2_Click(object sender, EventArgs e) { TcpMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + tbIP.Text + ":" + tbPorta.Text + "/");//ip local e porta do servidor myRpcClient.AttachDuplexOutputChannel(anOutputChannel); txtCliente.Enabled = true; txtCod.Enabled = true; txtValor.Enabled = true; SumButton.Enabled = true; button1.Enabled = true; button2.Enabled = false; tbPorta.Enabled = false; tbIP.Enabled = false; }
public void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("c:/tmp/tracefile.txt"); //EneterTrace.StartProfiler(); ChannelId = "tcp://127.0.0.1:6070/"; IMessagingSystemFactory anUnderlyingMessaging = new TcpMessagingSystemFactory(); TimeSpan aMaxOfflineTime = TimeSpan.FromMilliseconds(1000); MessagingSystem = new BufferedMonitoredMessagingFactory(anUnderlyingMessaging, aMaxOfflineTime, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(100)); ConnectionInterruptionFrequency = 100; }
public void init() { try { IRpcFactory rpcFactory = new RpcFactory(); RpcObj = rpcFactory.CreateClient<ILeiloeiro>(); TcpMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + IP + ":" + Porta + "/");//ip local e porta do servidor RpcObj.AttachDuplexOutputChannel(anOutputChannel); } catch (Exception ex) { throw new Exception("Erro: É necessario iniciar o servidor - " + ex.Message); } }
public Form1() { InitializeComponent(); // Create ProtoBuf serializer. mySerializer = new ProtoBufSerializer(); // Create broker client responsible for sending messages to the broker. IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory(mySerializer); myBrokerClient = aBrokerFactory.CreateBrokerClient(); // Create output channel to send messages via Tcp. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); myOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:7091/"); // Attach the output channel to the broker client to be able to send messages. myBrokerClient.AttachDuplexOutputChannel(myOutputChannel); }
public MainPage() { InitializeComponent(); // Create duplex message sender. // It can send messages and also receive messages. IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory(); myMessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender(); myMessageSender.ResponseReceived += MessageReceived; // Create TCP based messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/"); // Attach the duplex output channel to the message sender // and be able to send messages and receive messages. myMessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel); }
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); }
private void OpenConnection() { // Create Protocol Buffers serializer. ISerializer aSerializer = new ProtoBufSerializer(); // Create the synchronous message sender. // It will wait max 5 seconds for the response. // To wait infinite time use TimeSpan.FromMiliseconds(-1) or // default constructor new DuplexTypedMessagesFactory() IDuplexTypedMessagesFactory aSenderFactory = new DuplexTypedMessagesFactory(TimeSpan.FromSeconds(5), aSerializer); mySender = aSenderFactory.CreateSyncDuplexTypedMessageSender<ResponseMessage, RequestMessage>(); // Use TCP for the communication. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/"); // Attach the output channel and be able to send messages // and receive response messages. mySender.AttachDuplexOutputChannel(anOutputChannel); }
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 bool InitializeWorkerConnection() { // Create TCP messaging IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); Worker4504OutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4504/"); // Subscribe to response messages. Worker4504OutputChannel.ConnectionClosed += Worker4504OutputChannel_ConnectionClosed; Worker4504OutputChannel.ConnectionOpened += Worker4504OutputChannel_ConnectionOpened; Worker4504OutputChannel.ResponseMessageReceived += Worker4504OutputChannel_ResponseMessageReceived; // Open connection and be able to send messages and receive response messages. Worker4504OutputChannel.OpenConnection(); Log("Channel id : " + Worker4504OutputChannel.ChannelId); // Send a message. byte[] data = new byte[1048576]; // initialize 1MB data //byte[] data = new byte[10]; // initialize 1MB data Random random = new Random(); random.NextBytes(data); Worker4504OutputChannel.SendMessage(data); Log("Sent data length : " + data.Length); // Close connection. //Worker4504OutputChannel.CloseConnection(); return true; }
private bool Worker4504_Initialize() { // Create TCP messaging IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); Worker4504_OutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4504/"); // Subscribe to response messages. Worker4504_OutputChannel.ConnectionClosed += Worker4504_ConnectionClosed; Worker4504_OutputChannel.ConnectionOpened += Worker4504_ConnectionOpened; Worker4504_OutputChannel.ResponseMessageReceived += Worker4504_ResponseMessageReceived; // Open connection and be able to send messages and receive response messages. Worker4504_OutputChannel.OpenConnection(); if (Worker4504_OutputChannel.IsConnected) { return true; } else { return false; } }
private bool Command_Initialize() { // Create duplex message sender. // It can send messages and also receive messages. IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory(); Command_MessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender(); Command_MessageSender.ResponseReceived += Command_ResponseReceived; // Create TCP based messaging. IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4502/"); // Attach the duplex output channel to the message sender // and be able to send messages and receive messages. try { Command_MessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel); } catch (Exception e) { Log(e.Message); } if (Command_MessageSender.IsDuplexOutputChannelAttached) { Log("Initialized connection."); return true; } else { Log("Unable to initialize connection"); return false; } }
// The method is called when the button to send message is clicked. private void SendMessage_Click(object sender, RoutedEventArgs e) { // Create message sender sending request messages of type Person and receiving responses of type string. IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory(); myMessageSender = aTypedMessagesFactory.CreateDuplexTypedMessageSender<byte[], byte[]>(); myMessageSender.ResponseReceived += ResponseReceived; // Create messaging based on TCP. IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory(); IDuplexOutputChannel aDuplexOutputChannel = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/"); // Attach output channel and be able to send messages and receive response messages. myMessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel); myMessageSender.SendRequestMessage(GetBytes(textBox1.Text)); }
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; }
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"); }