static async Task Main(string[] args) { var icontainer = new NetxSClientBuilder() .ConfigSSL(p => //设置SSL加密 { p.Certificate = certificate; p.IsUse = true; }) .ConfigCompress(p => p.Mode = Netx.CompressType.None) // .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) //如何保存Session需要下次打开 不用登陆 .ConfigConnection(p => //配置连接 { p.Host = "127.0.0.1"; //IP p.Port = 3000; //端口 p.ServiceName = "MessageService"; //服务名称 p.VerifyKey = "123123"; //密码 }); var Current = icontainer.Build(); //生成一个CLIENT Re: var(success, my) = await Current.Get <IServer>().CheckLogIn(); var rand = new Random(); if (!success) { my = new User { UserName = $"user_{rand.Next(1, 1000000)}", PassWord = "******", NickName = $"{rand.Next(1, 1000000)}" }; var(check_register, msg) = await Current.Get <IServer>().Register(my); if (!check_register) { Console.WriteLine(msg); return; } (success, msg) = await Current.Get <IServer>().LogOn(my.UserName, my.PassWord); if (!success) { Console.WriteLine(msg); return; } goto Re; } for (int i = 0; i < 1000; i++) { await Current.Get <IServer>().Say(-1, "11111111"); } }
static Dependency() { var icontainer = new NetxSClientBuilder() .ConfigureLogSet(p => { p.AddDebug().SetMinimumLevel(LogLevel.Trace); //添加DEBUG日记输出 }) .ConfigSSL(p => //设置SSL加密 { p.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2( $"{System.Windows.Forms.Application.StartupPath}/client.pfx" , "testPassword"); p.IsUse = true; }) // .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) //如何保存Session需要下次打开 不用登陆 .ConfigConnection(p => //配置连接 { p.Host = "127.0.0.1"; //IP p.Port = 3000; //端口 p.ServiceName = "MessageService"; //服务名称 p.VerifyKey = "123123"; //密码 }); Client = icontainer.Build(); //生成一个CLIENT IContainer = icontainer.Container; }
static async Task Main(string[] args) { var client = new NetxSClientBuilder() .ConfigConnection(p => //配置服务器IP { p.Host = "127.0.0.1"; p.Port = 1006; p.VerifyKey = "123123"; p.MaxPackerSize = 256 * 1024; }) //设置SESSION 的存储方式,SESSION 用来记录你的TOKEN,方便断线重连不会丢失工作进度,我们存储在内存,也可以保存成文件 // .ConfigSessionStore(() => new Netx.Client.Session.SessionMemory()) // .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) .Build(); client.LoadInstance(new ClientController()); //加载客户端控制器供服务区主动调用, client.Open(); //你可以先连接服务器,或者不连接,如果你没有OPEN 那么调用的时候 var server = client.Get <IServer>(); //根据接口返回 服务器调用的实例 var res = await server.Login("test", "123123"); Console.WriteLine(res); }
static Dependency() { var icontainer = new NetxSClientBuilder() .ConfigureLogSet(p => { p.AddDebug().SetMinimumLevel(LogLevel.Trace); //添加DEBUG日记输出 }) .ConfigSSL(p => //设置SSL加密 { p.Certificate = certificate; p.IsUse = true; }) .ConfigCompress(p => p.Mode = Netx.CompressType.None) // .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) //如何保存Session需要下次打开 不用登陆 .ConfigConnection(p => //配置连接 { p.Host = "127.0.0.1"; //IP p.Port = 3000; //端口 p.ServiceName = "MessageService"; //服务名称 p.VerifyKey = "123123"; //密码 }); Client = icontainer.Build(); //生成一个CLIENT IContainer = icontainer.Container; }
static Dependency() { var icontainer = new NetxSClientBuilder() .ConfigureLogSet(p => { p.AddDebug().SetMinimumLevel(LogLevel.Trace); }) //.ConfigSSL(p => //{ // p.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2( // $"{System.Windows.Forms.Application.StartupPath}/client.pfx" // , "testPassword"); // p.IsUse = true; //}) // .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) //如何需要下次打开 不用登陆 .ConfigConnection(p => { p.Host = "127.0.0.1"; p.Port = 3000; p.ServiceName = "MessageService"; p.VerifyKey = "123123"; }); Client = icontainer.Build(); IContainer = icontainer.Container; }
static async Task Main(string[] args) { int clientCout = Environment.ProcessorCount * 4; var clientBuilder = new NetxSClientBuilder() .ConfigConnection(p => { p.Host = args.Length == 0? "127.0.0.1":args[0]; p.Port = args.Length == 0 ? 1005:args.Length >= 2?int.Parse(args[1]): 1005; p.VerifyKey = args.Length == 0 ? "123123":args.Length >= 3?args[2]:"123123"; p.RequestTimeOut = 0; }) //.ConfigSSL(p => //{ // p.IsUse = true; // p.Certificate = certificate; //}) .ConfigSessionStore(() => { return(new Netx.Client.Session.SessionMemory()); }); var client0 = clientBuilder.Build(); List <Task <(long m, int count)> > tasks = new List <Task <(long m, int count)> >(clientCout); tasks.Add(Run(client0)); for (int i = 0; i < clientCout - 1; i++) { tasks.Add(Run(clientBuilder.Provider.CreateScope().ServiceProvider.GetRequiredService <NetxSClient>())); } double allm = 0.0; double count = 0.0; foreach (var item in tasks) { var r = await item; allm += r.m; count += r.count; } Console.WriteLine(count + "/" + (allm / clientCout)); float mc = (float)(count / (allm / clientCout)); float sc = mc * 1000; Console.WriteLine(sc + " TPS"); var icount = await client0.Get <IServer>().GetAllCount(); Console.WriteLine($"i is {icount}"); Console.ReadLine(); }
static async Task Main(string[] args) { var client = new NetxSClientBuilder() .ConfigConnection(p => //配置服务器IP { p.Host = "192.168.1.235"; p.Port = 6666; p.VerifyKey = "123123"; p.MaxPackerSize = 256 * 1024; }) //设置SESSION 的存储方式,SESSION 用来记录你的TOKEN,方便断线重连不会丢失工作进度,我们存储在内存,也可以保存成文件 // .ConfigSessionStore(() => new Netx.Client.Session.SessionMemory()) .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) .Build(); client.LoadInstance(new ClientTestController()); //加载客户端控制器供服务区主动调用, client.Open(); //你可以先连接服务器,或者不连接,如果你没有OPEN 那么调用的时候 var server = client.Get <IServer>(); //根据接口返回 服务器调用的实例 await server.Print(5); await server.RunTest("joy"); var x = await server.ToClientAddOne(1); Console.WriteLine("x:{0}", x); await server.Print2(6, "my name is"); var stop = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < 100000; i++) { await server.Add(1, i); } var r = await server.RecursiveTest(10000); Console.WriteLine($"{r} {stop.ElapsedMilliseconds}"); var res = new LogOn { Username = "******", Password = "******" }; var(success, msg) = await server.LogOn(res); Console.WriteLine($"{success} {msg}"); var res2 = await server.LogOn2(("username", "password")); Console.WriteLine($"{res2.Success} {res2.Msg}"); Console.ReadLine(); }
public IFSClient(string host, int port, string key) { INetxtBuilder = new NetxSClientBuilder() .ConfigConnection(p => //配置服务器IP { p.Host = host; p.Port = port; p.VerifyKey = key; p.ServiceName = "IFServ"; }) .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()); Client = INetxtBuilder.Build(); }
static NetxHandler() { for (int i = 0; i < 3; i++) { var client = new NetxSClientBuilder() .ConfigConnection(p => { p.Host = Setting.SERVER_HOST; p.Port = 50054; p.VerifyKey = "11111"; p.ServiceName = "hellowordservice"; p.RequestTimeOut = 0; }) .Build(); mClients.Add(client); } }
static async Task Main(string[] args) { var client = new NetxSClientBuilder() .ConfigConnection(p => { p.Host = "127.0.0.1"; p.Port = 50054; p.RequestTimeOut = 0; }) .ConfigObjFormat(() => new NetxSerializes.JSONSerializes()) .Build(); var a = await client.Get <ITestServer>().SayHello(new HelloRequest { Name = "123123" }); Console.WriteLine(a.Message); Console.ReadLine(); }
public void ConfigInstance(string ip, int port) { Dispose(); var clientbuilder = new NetxSClientBuilder() .ConfigConnection(option => { option.Host = ip; option.Port = port; option.ServiceName = "MessageService"; option.VerifyKey = "123123"; option.ConnectedTimeOut = 10000; }) .ConfigureLogSet(p => { }) .ConfigSessionStore(() => new Netx.Client.Session.SessionFile(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))) .ConfigSSL(option => { var assembly = IntrospectionExtensions.GetTypeInfo(typeof(ClientService)).Assembly; using (Stream stream = assembly.GetManifestResourceStream("ChaTRoomApp.client.pfx")) { using (BinaryReader read = new BinaryReader(stream)) { var data = read.ReadBytes((int)stream.Length); option.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(data, "testPassword"); option.IsUse = true; } } }); Client = clientbuilder.Build(); service = clientbuilder.Provider; }
static async Task Main(string[] args) { var client = new NetxSClientBuilder() .ConfigConnection(p => //配置服务器IP { p.Host = "127.0.0.1"; p.Port = 1006; p.VerifyKey = "123123"; }) //设置SESSION 的存储方式,SESSION 用来记录你的TOKEN,方便断线重连不会丢失工作进度,我们存储在内存,也可以保存成文件 // .ConfigSessionStore(() => new Netx.Client.Session.SessionMemory()) .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) .Build(); client.LoadInstance(new ClientTestController()); //加载客户端控制器供服务区主动调用, //client.Open(); 你可以先连接服务器,或者不连接,如果你没有OPEN 那么调用的时候 var server = client.Get <IServer>(); //根据接口返回 服务器调用的实例 var pcs = await server.Testnull(Guid.NewGuid(), "XCM", 123); var cvs = await server.TestPermission(); try { cvs = await server.TestPermission2(); } catch (NetxException er) { client.Log.Error(er.Message); } for (int i = 0; i < 1000; i++) { var c = await server.Add(i, 0); //调用RPC client.Log.Trace(c); } for (int i = 0; i < 1000; i++) { var c = await server.AddActor(i, 0); //调用ACTOR client.Log.Trace(c); } for (int i = 0; i < 1000; i++) { var c = await server.RotueToAddActor(i, 0); //调用RPC TO ACTOR 路由版 client.Log.Trace(c); } for (int i = 0; i < 1000; i++) { var c = await server.ClientAdd(i, 0); //调用RPC,这个服务器将请求路由到自己的控制器中 自己算 Add client.Log.Trace(c); } try { await server.ClientAddOne(1); //测试异常 } catch (NetxException er) { client.Log.Error(er); } var stop = System.Diagnostics.Stopwatch.StartNew(); //测试双向递归函数 int a = await server.RecursiveTest(1000); stop.Stop(); client.Log.Info($"recursive is {a} time:{stop.ElapsedMilliseconds} ms"); try { await server.TestTimeOut(); //超时测试 } catch (NetxException er) { client.Log.Error(er.Message); } server.RunMsg("close"); server.Finsh(); //断线测试 Console.ReadLine(); }
static async Task Main(string[] args) { int clientCout = Environment.ProcessorCount * 8; var clientBuilder = new NetxSClientBuilder() .ConfigConnection(p => { p.Host = args.Length == 0 ? "127.0.0.1" : args[0]; p.Port = args.Length == 0 ? 1005 : args.Length >= 2 ? int.Parse(args[1]) : 1005; p.VerifyKey = args.Length == 0 ? "123123" : args.Length >= 3 ? args[2] : "123123"; p.RequestTimeOut = 0; p.MaxPackerSize = 256 * 1024; }) .ConfigSSL(p => { p.IsUse = true; p.Certificate = certificate; }) .ConfigCompress(p => p.Mode = Netx.CompressType.None) .ConfigSessionStore(() => { return(new Netx.Client.Session.SessionMemory()); }); var client0 = clientBuilder.Build(); var server = client0.Get <IServer>(); List <Task> RunList = new List <Task>(); int cc = 100; int threadcount = 60; var x = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < threadcount; i++) { async Task Runs() { int xcount = i + cc; while (i < xcount) { int c = i + 1; i = await server.AddOne(i); if (c != i) { throw new Exception("error value"); } } } RunList.Add(Runs()); } await Task.WhenAll(RunList); x.Stop(); var time = x.ElapsedMilliseconds; double all = cc * threadcount; Console.WriteLine(time + " ms"); Console.WriteLine((all / time * 1000.0) + " TPS"); Console.ReadLine(); List <Task <(long m, int count)> > tasks = new List <Task <(long m, int count)> >(clientCout) { Run(client0) }; for (int i = 0; i < clientCout - 1; i++) { tasks.Add(Run(clientBuilder.Provider.CreateScope().ServiceProvider.GetRequiredService <NetxSClient>())); } double allm = 0.0; double count = 0.0; foreach (var item in tasks) { var r = await item; allm += r.m; count += r.count; } Console.WriteLine(count + "/" + (allm / clientCout)); float mc = (float)(count / (allm / clientCout)); float sc = mc * 1000; Console.WriteLine(sc + " TPS"); var icount = await client0.Get <IServer>().GetAllCount(); Console.WriteLine($"i is {icount}"); Console.ReadLine(); }
static async Task Main() { var client = new NetxSClientBuilder() .ConfigConnection(p => //配置服务器IP { p.Host = "127.0.0.1"; p.Port = 3000; p.VerifyKey = "123123"; }) .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) .Build(); client.LoadInstance(new ClientController()); var server = client.Get <IServer>(); var r = await server.Add(1, 2); r = await server.AddOne(r); Console.WriteLine(r); var servernew = client.Get <IServerNew>(); r = await servernew.AddTow(r); Console.WriteLine(r); servernew.Run(r.ToString()); var serverold = client.Get <IServerOld>(); r = await serverold.AddOne(r); Console.WriteLine(r); var serverdef = client.Get <IServerDef>(); r = await serverdef.Add3(r); Console.WriteLine(r); Console.WriteLine("---------next actor------------"); var actor = client.Get <IActors>(); r = await actor.Add(1, 2); r = await actor.AddOne(r); Console.WriteLine(r); var actornew = client.Get <IActorsNew>(); r = await actornew.AddTow(r); Console.WriteLine(r); actornew.Run(r.ToString()); var actorold = client.Get <IActorsOld>(); r = await actorold.AddOne(r); Console.WriteLine(r); var actordef = client.Get <IActorsDef>(); r = await actordef.Add3(r); Console.WriteLine(r); try { await client.Get <IActorsSub>().Sub(5, 4); }catch (Netx.NetxException er) { Console.WriteLine(er.Message); } Console.ReadLine(); }
//static X509Certificate certificate = new X509Certificate2(Environment.CurrentDirectory + "/client.pfx", "testPassword"); static async Task Main(string[] args) { var client = new NetxSClientBuilder() .ConfigConnection(p => //配置服务器IP { p.Host = "127.0.0.1"; p.Port = 6666; p.VerifyKey = "123123"; p.MaxPackerSize = 256 * 1024; }) //设置SESSION 的存储方式,SESSION 用来记录你的TOKEN,方便断线重连不会丢失工作进度,我们存储在内存,也可以保存成文件 // .ConfigSessionStore(() => new Netx.Client.Session.SessionMemory()) .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) //.ConfigSSL(option => //{ // option.IsUse = true; // option.SslStreamInit = async (stream) => // { // var sslstream = new SslStream(stream, false, (sender, certificate, chain, errors) => true, // (sender, host, certificates, certificate, issuers) => certificate); // try // { // await sslstream.AuthenticateAsClientAsync("localhost"); // } // catch (Exception er) // { // Console.WriteLine(er.Message); // return null; // } // return sslstream; // }; //}) .Build(); client.LoadInstance(new ClientTestController()); //加载客户端控制器供服务区主动调用, client.Open(); //你可以先连接服务器,或者不连接,如果你没有OPEN 那么调用的时候 var server = client.Get <IServer>(); //根据接口返回 服务器调用的实例 var stop = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < 1000; i++) { var _ = await server.Add(1, 2); //调用RPC } Console.WriteLine(stop.ElapsedMilliseconds); var data = new List <Guid>(); for (int i = 0; i < 1000; i++) { data.Add(Guid.NewGuid()); } var redata = await server.TestMaxBuffer(data); var pcs = await server.Testnull(Guid.NewGuid(), "XCM", 123); var cvs = await server.TestPermission(); try { cvs = await server.TestPermission2(); } catch (NetxException er) { client.Log.Error(er.Message); } for (int i = 0; i < 1000; i++) { var c = await server.Add(i, 0); //调用RPC client.Log.Trace(c); } for (int i = 0; i < 1000; i++) { var c = await server.AddActor(i, 0); //调用ACTOR client.Log.Trace(c); } for (int i = 0; i < 1000; i++) { var c = await server.RotueToAddActor(i, 0); //调用RPC TO ACTOR 路由版 client.Log.Trace(c); } for (int i = 0; i < 1000; i++) { var c = await server.ClientAdd(i, 0); //调用RPC,这个服务器将请求路由到自己的控制器中 自己算 Add client.Log.Trace(c); } try { await server.ClientAddOne(1); //测试异常 } catch (NetxException er) { client.Log.Error(er); } stop = System.Diagnostics.Stopwatch.StartNew(); //测试双向递归函数 int a = await server.RecursiveTest(1000); stop.Stop(); client.Log.Info($"recursive is {a} time:{stop.ElapsedMilliseconds} ms"); try { await server.TestTimeOut(); //超时测试 } catch (NetxException er) { client.Log.Error(er.Message); } server.TestErr(); server.TestAsyncErr(); server.RunMsg("close"); server.Finsh(); //断线测试 Console.ReadLine(); }
static async Task Main(string[] args) { var client = new NetxSClientBuilder() .ConfigConnection(p => //配置服务器IP { p.Host = "127.0.0.1"; p.Port = 6666; p.VerifyKey = "123123"; p.MaxPackerSize = 256 * 1024; }) .ConfigSSL(p => { p.IsUse = false; p.Certificate = null; }) //设置SESSION 的存储方式,SESSION 用来记录你的TOKEN,方便断线重连不会丢失工作进度,我们存储在内存,也可以保存成文件 // .ConfigSessionStore(() => new Netx.Client.Session.SessionMemory()) .ConfigSessionStore(() => new Netx.Client.Session.SessionFile()) .Build(); client.LoadInstance(new ClientTestController()); //加载客户端控制器供服务区主动调用, client.Open(); //你可以先连接服务器,或者不连接,如果你没有OPEN 那么调用的时候 var server = client.Get <IServer>(); //根据接口返回 服务器调用的实例 // await server.Print(5); // 测试基本类型 { (bool, sbyte, byte, short, ushort, int, uint)v = (true, 2, 3, 4, 5, 6, 7); var t = await server.test_base_type(v); if (t != v) { throw new Exception("base test error"); } (long, ulong, float, double)v1 = (8, 9, 1.1f, 2.2222); var t1 = await server.test_base_type(v1); if (t1 != v1) { throw new Exception("base test error"); } } // 测字符串 { (string, string, string)v = ("test", "test", null); var t = await server.test_string(v); if (t != v) { throw new Exception("base test error"); } } //测试buff { (List <byte>, List <byte>, List <byte>)v = (new List <byte> { 1, 2, 3 }, new List <byte> { 1, 2, 3 }, null); var t = await server.test_buff(v); if (t.Item1.Count != 3 || t.Item2.Count != 3 || t.Item3 != null) { throw new Exception("base test error"); } } // 测试对象 { var v = new Foo(); var t = await server.test_struct(v); if (!t.Equals(v)) { throw new Exception("base test error"); } } await server.RunTest(null); await server.RunTest("joy"); //var x = await server.ToClientAddOne(1); //Console.WriteLine("x:{0}",x); await server.Print2(6, "my name is"); var stop = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < 100000; i++) { await server.Add(1, i); } var r = await server.RecursiveTest(10000); Console.WriteLine($"{r} {stop.ElapsedMilliseconds}"); var res = new LogOn { Username = "******", Password = "******" }; var(success, msg) = await server.LogOn(res); Console.WriteLine($"{success} {msg}"); var res2 = await server.LogOn2(("username", "password")); Console.WriteLine($"{res2.Success} {res2.Msg}"); Console.ReadLine(); }