public static IApplicationBuilder UseTcpGuardServer(this IApplicationBuilder app, QpWebSocketServerOptions options) { if (string.IsNullOrEmpty(options.ServerProgram)) { options.ServerProgram = typeof(TcpGuardServerMiddlewareExtensions).Assembly.GetName().Name; } if (string.IsNullOrEmpty(options.Path)) { options.Path = "/"; } if (options.InstructionSet == null || options.InstructionSet.Length == 0) { options.InstructionSet = new[] { TcpGuard.Core.Protocol.V1.Instruction.Instance } } ; QpWebSocketServer server = null; app.UseQuickProtocol(options, out server); server.Start(); var commandExecuterManager = new CommandExecuterManager(); commandExecuterManager.UseTcpGuardServer(); server.ChannelConnected += (sender, e) => e.CommandExecuter = commandExecuterManager; return(app); } }
static void Main(string[] args) { Quick.Protocol.Utils.LogUtils.LogConnection = true; //Quick.Protocol.Utils.LogUtils.LogPackage = true; //Quick.Protocol.Utils.LogUtils.LogHeartbeat = true; //Quick.Protocol.Utils.LogUtils.LogNotice = true; //Quick.Protocol.Utils.LogUtils.LogSplit = true; //Quick.Protocol.Utils.LogUtils.LogContent = true; var commandExecuterManager = new CommandExecuterManager(); commandExecuterManager.Register <Quick.Protocol.Commands.PrivateCommand.Request, Quick.Protocol.Commands.PrivateCommand.Response>((handler, req) => { return(new Quick.Protocol.Commands.PrivateCommand.Response() { Content = req.Content }); }); var serverOptions = new Quick.Protocol.Pipeline.QpPipelineServerOptions() { PipeName = "Quick.Protocol", Password = "******", ServerProgram = nameof(PipelineServer) + " 1.0" }; serverOptions.RegisterCommandExecuterManager(commandExecuterManager); var server = new Quick.Protocol.Pipeline.QpPipelineServer(serverOptions); server.ChannelConnected += Server_ChannelConnected; server.ChannelDisconnected += Server_ChannelDisconnected; try { server.Start(); Console.WriteLine($"服务启动成功!"); } catch (Exception ex) { Console.WriteLine($"服务启动失败!" + ex.ToString()); } Console.ReadLine(); server.Stop(); }
public Server(QpTcpServerOptions options) { server = new QpTcpServer(options); commandExecuterManager = new CommandExecuterManager(); commandExecuterManager.UseTcpGuardServer(); }
public static void UseTcpGuardServer(this CommandExecuterManager commandExecuterManager) { commandExecuterManager.Add <GetVersionCommand>(new TcpGuard.Core.CommandExecuters.GetVersion()); commandExecuterManager.Add <ConnectCommand>(new TcpGuard.Core.CommandExecuters.Connect()); }