private async static Task Process() { using (var client = new ChannelTcpClient <object>( new MicroMessageEncoder(new JsonSerializer()), new MicroMessageDecoder(new JsonSerializer()))) { ObjectFactory.Configure(x => x.Scan(z => { z.AssemblyContainingType <IRequestResponseService>(); z.With(new ServiceFactoryConvention(new ServiceExecutor(client))); z.AddAllTypesOf <IMicroService>(); })); await client.ConnectAsync(IPAddress.Parse("127.0.0.1"), 1234); var srv = ObjectFactory.GetInstance <IRequestResponseService>(); var result = srv.Call( new TestContract { Text = "Hello text 1" }, new TestContract { Text = "Hello text 2" }); Console.WriteLine(result); await client.CloseAsync(); } }
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> /// Start client (will autoconnect if getting disconnected) /// </summary> /// <param name="address">The address for the CQS server.</param> /// <param name="port">The port that the CQS server is listening on.</param> /// <returns></returns> public async Task StartAsync(IPAddress address, int port) { _endPoint = new IPEndPoint(address, port); await _client.ConnectAsync(_endPoint.Address, _endPoint.Port); }