public static void Main() { try { TTransport transport = new TSocket("localhost", 9090); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
public static void Main() { try { TTransport transport = new TSocket("localhost", 7777); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Debug.Log("ping()"); int sum = client.add(1, 1); Debug.Log("1+1={0}" + sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Debug.Log("Whoa we can divide by 0"); } catch (InvalidOperation io) { Debug.Log("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Debug.Log("15-10={0}" + diff); } catch (InvalidOperation io) { Debug.Log("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Debug.Log("Check log: {0}" + log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Debug.Log(x.StackTrace); } }
static async Task Run() { try { var transport = new TSocket("localhost", 9090, 100000); TBufferedTransport transportBuff = new TBufferedTransport(transport, 2048); TProtocol protocol = new TBinaryProtocol(transportBuff); transport.Open(); Calculator.Client client = new Calculator.Client(protocol); Console.WriteLine($"run Client host:{transport.Host},port:{transport.Port}"); await client.pingAsync(); int testCount = 100000; var sw = Stopwatch.StartNew(); foreach (var m in Enumerable.Range(0, testCount)) { int sum = client.add(1, 1); } sw.Stop(); Console.WriteLine($"TBufferedTransport Execute client.add(1, 1) do:{testCount} ms:{sw.ElapsedMilliseconds}"); sw.Restart(); foreach (var m in Enumerable.Range(0, testCount)) { int sum = await client.addAsync(1, 1); } sw.Stop(); Console.WriteLine($"TBufferedTransport Execute client.addAsync(1, 1) do:{testCount} ms:{sw.ElapsedMilliseconds}"); await client.calculateAsync(1, new Work() { Op = Operation.ADD, Comment = "add Comment" }); //InvalidOperation transport.Close(); } catch (InvalidOperation ex) { Console.WriteLine($"InvalidOperation why:{ex.Why} op:{ex.WhatOp} ex:{ex.GetType()} message:{ex.Message} {ex.StackTrace}"); } catch (TApplicationException x) { Console.WriteLine($"TApplicationException ex:{x.Type} message:{x.Message} {x.StackTrace}"); } }
public static void Main(string[] args) { /* +-------------------------------------------+ | Server | | (single-threaded, event-driven etc) | +-------------------------------------------+ | Processor | | (compiler generated) | +-------------------------------------------+ | Protocol | | (JSON, compact etc) | +-------------------------------------------+ | Transport | | (raw TCP, HTTP etc) | +-------------------------------------------+ */ try{ TTransport transport = new TSocket("localhost", 9090); // transport TProtocol protocol = new TBinaryProtocol(transport); // protocol Calculator.Client client = new Calculator.Client(protocol); // processor transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0 " + quotient); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } Console.WriteLine ("Hello World!"); }
static void Main(string[] args) { if (args.Length < 4) { Console.WriteLine("server [ns] [hc] [keyname] [key]"); return; } var ns = args[0]; var hc = args[1]; var keyname = args[2]; var key = args[3]; var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(keyname, key); var sendAddress = new Uri($"sb://{ns}/{hc}"); var relayClient = new HybridConnectionClient(sendAddress, tokenProvider); try { var relayConnection = relayClient.CreateConnectionAsync().GetAwaiter().GetResult(); TTransport transport = new TStreamTransport(relayConnection, relayConnection); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
public async Task Run(string sendAddress, string sendToken) { try { var relayClient = new RelayClient(sendAddress, TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken)); var relayConnection = relayClient.Connect(); TTransport transport = new TStreamTransport(relayConnection, relayConnection); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
public async Task Run(string sendAddress, string sendToken) { try { var relayClient = new RelayClient(sendAddress, TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken)); var relayConnection = relayClient.Connect(); TTransport transport = new TStreamTransport(relayConnection, relayConnection); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }