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"); }
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 Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); SynchronousMessagingSystemFactory anUnderlyingMessaging = new SynchronousMessagingSystemFactory(); ChannelId = "MyChannel1"; MessagingSystemFactory = new AuthenticatedMessagingFactory(anUnderlyingMessaging, GetLoginMessage, GetHandshakeResponseMessage, GetHandshakeMessage, VerifyHandshakeResponseMessage, HandleAuthenticationCancelled) { AuthenticationTimeout = TimeSpan.FromMilliseconds(2000) }; myHandshakeSerializer = new AesSerializer("Password123"); }