private static async Task ExecuteClient(ChannelTcpListener server) { var client = new MyProtocolClient(); await client.ConnectAsync(IPAddress.Loopback, server.LocalPort); await client.SendAsync(new Ping { Name = "TheClient" }); var response = await client.ReceiveAsync(); Console.WriteLine("Client received: " + response); }
/// <summary> /// Initializes a new instance of the <see cref="LiteServer" /> class. /// </summary> public LiteServer(LiteServerConfiguration configuration) { if (configuration == null) throw new ArgumentNullException("configuration"); _modules = configuration.Modules.Build(); var config = new ChannelTcpListenerConfiguration(configuration.DecoderFactory, configuration.EncoderFactory); _listener = new ChannelTcpListener(config); if (configuration.Certificate != null) _listener.ChannelFactory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(configuration.Certificate)); _listener.MessageReceived = OnClientMessage; _listener.ClientConnected += OnClientConnect; _listener.ClientDisconnected += OnClientDisconnect; }
static void Main(string[] args) { var server = new ChannelTcpListener(); server.MessageReceived = OnServerReceivedMessage; server.Start(IPAddress.Any, 0); var client = new ChannelTcpClient <object>(new MicroMessageEncoder(new DataContractMessageSerializer()), new MicroMessageDecoder(new DataContractMessageSerializer())); client.ConnectAsync(IPAddress.Loopback, server.LocalPort).Wait(); client.SendAsync(new FileStream("TextSample.txt", FileMode.Open)).Wait(); Console.ReadLine(); }
/// <summary> /// Initializes a new instance of the <see cref="CqsServer" /> class. /// </summary> public CqsServer(ICommandBus commandBus, IQueryBus queryBus, IEventBus eventBus, IRequestReplyBus requestReplyBus) { _commandBus = commandBus; _queryBus = queryBus; _eventBus = eventBus; _requestReplyBus = requestReplyBus; var config = new ChannelTcpListenerConfiguration(CreateDecoder, CreateEncoder); _listener = new ChannelTcpListener(config); _listener.MessageReceived = OnClientMessage; _requestMethod = GetType().GetMethod("ExecuteRequest", BindingFlags.NonPublic | BindingFlags.Instance); _commandMethod = GetType().GetMethod("ExecuteCommand", BindingFlags.NonPublic | BindingFlags.Instance); _queryMethod = GetType().GetMethod("ExecuteQuery", BindingFlags.NonPublic | BindingFlags.Instance); }
static void Main(string[] args) { var config = new ChannelTcpListenerConfiguration( () => new MyProtocolDecoder(), () => new MyProtocolEncoder() ); var server = new ChannelTcpListener(config); server.MessageReceived += OnServerMessageReceived; server.Start(IPAddress.Any, 0); ExecuteClient(server).Wait(); Console.WriteLine("Demo completed"); Console.ReadLine(); }
/// <summary> /// Initializes a new instance of the <see cref="LiteServer" /> class. /// </summary> public LiteServer(LiteServerConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } _modules = configuration.Modules.Build(); var config = new ChannelTcpListenerConfiguration(configuration.DecoderFactory, configuration.EncoderFactory); _listener = new ChannelTcpListener(config); if (configuration.Certificate != null) { _listener.ChannelFactory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(configuration.Certificate)); } _listener.MessageReceived = OnClientMessage; _listener.ClientConnected += OnClientConnect; _listener.ClientDisconnected += OnClientDisconnect; }