/// <summary> /// new /// </summary> /// <param name="socketService"></param> /// <param name="protocol"></param> /// <param name="socketBufferSize"></param> /// <param name="messageBufferSize"></param> /// <param name="maxMessageSize"></param> /// <param name="maxConnections"></param> /// <exception cref="ArgumentNullException">socketService is null.</exception> /// <exception cref="ArgumentNullException">protocol is null.</exception> /// <exception cref="ArgumentOutOfRangeException">maxMessageSize</exception> /// <exception cref="ArgumentOutOfRangeException">maxConnections</exception> public SocketServer(IServerHandler handler, Protocol.IProtocol protocol, int socketBufferSize, int messageBufferSize, int maxMessageSize, int maxConnections) : base(socketBufferSize, messageBufferSize) { if (handler == null) { throw new ArgumentNullException("handler"); } if (protocol == null) { throw new ArgumentNullException("protocol"); } if (maxMessageSize < 1) { throw new ArgumentOutOfRangeException("maxMessageSize"); } if (maxConnections < 1) { throw new ArgumentOutOfRangeException("maxConnections"); } this._handler = handler; this._protocol = protocol; this._maxMessageSize = maxMessageSize; this._maxConnections = maxConnections; }
private IServerHandler handle(string words, Socket client) { Message <JObject> msg = JsonConvert.DeserializeObject <Message <JObject> >(words); IServerHandler handler = null; switch (msg.MessageType) { case MessageType.C_LogIn: // 登录 handler = _loginHandler; break; case MessageType.Heart: // 心跳 handler = _heartHandler; break; case MessageType.C_SwapMsg: // 交换数据 handler = _swapMsgHandler; break; default: throw new Exception($"未知的通讯指令 {msg.MessageType}"); } handler.HandlerMsg(this, client, msg); return(handler); }
public void StartListening(IPEndPoint localEP, IServerHandler <Type> handler) { // stop if started StopListening(); this.handler = handler; // Create a TCP/IP socket. listeningTcpSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Bind the socket to the local endpoint and listen for incoming connections. try { listeningTcpSocket.Bind(localEP); listeningTcpSocket.Listen(100); Console.WriteLine("TCP : Listening on {0}", listeningTcpSocket.LocalEndPoint); AcceptNext(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); StopListening(); throw ex; } }
public ChatHostedService(IOptions <ServerConfig> options, ServerOptions serverOptions, IServerHandler serverHandler, IUserRepository userRepository) { this.serverConfig = options.Value; this.serverOptions = serverOptions; this.serverHandler = serverHandler; this.userRepository = userRepository; }
public static IServer CreateTcpServer(IServerHandler handler, IPacket packet) { TcpServer server = new TcpServer(); server.Handler = handler; server.Packet = packet; return(server); }
public static IServer CreateTcpServer(NetConfig config, IServerHandler handler, IPacket packet) { TcpServer server = new TcpServer(config); server.Handler = handler; server.Packet = packet; return(server); }
public UdpServer(IServerHandler handler) { this._data = new byte[2048]; this._handler = handler; this._handler.Server = this; this._queue = new Queue <SendData>(); this._queueMutex = new Mutex(); }
public TcpConnection(Socket socket, IServerHandler <Type> handler) { this.socket = socket; this.handler = handler; asyncReadCalback = new AsyncCallback(ReadCallback); asyncSendCallback = new AsyncCallback(SendCallback); }
/// <summary> /// Initialize new client /// </summary> /// <param name="addr">IP address to connect to</param> /// <param name="port">Port to connect to</param> /// <param name="serverHandler">Instance of server handler interface</param> public Client(IPAddress addr, int port, IServerHandler serverHandler) { this.Port = port; this.Address = addr; this.serverHandler = serverHandler; this.client = new TcpClient(); }
public static IServer CreateTcpServer(IServerHandler handler, IPacket packet, ServerOptions options = null) { TcpServer server = new TcpServer(options); server.Handler = handler; server.Packet = packet; return(server); }
public void StopListening() { if (listeningTcpSocket != null) { listeningTcpSocket.Close(); listeningTcpSocket = null; } handler = null; }
public void StopListening() { if (listeningClient != null) { listeningClient.Close(); listeningClient = null; } handler = null; establishedConnections.Clear(); }
public void StartListening(IPEndPoint localEP, IServerHandler <Type> handler) { // stop if started StopListening(); this.handler = handler; listeningClient = new UdpClient(localEP); Console.WriteLine("UDP : Listening on {0}", localEP); ReadNext(); }
/// <summary> /// 使用默认配置参数的构造函数 /// </summary> /// <param name="handler"></param> public SocketServer(IServerHandler handler,IEncoder encoder, IDecoder decoder) : base(DefaultConfigure.SocketBufferSize, DefaultConfigure.MessageBufferSize) { if (handler == null) throw new ArgumentNullException("handler"); if (encoder == null) throw new ArgumentNullException("encoder"); if (decoder == null) throw new ArgumentNullException("decoder"); this._handler = handler; this._protocol = new DefaultBinaryProtocol(); this._encoder = encoder; this._decoder = decoder; this._maxMessageSize = DefaultConfigure.MaxMessageSize; this._maxConnections = DefaultConfigure.MaxConnections; }
/// <summary> /// new /// </summary> /// <param name="socketService"></param> /// <param name="protocol"></param> /// <param name="socketBufferSize"></param> /// <param name="messageBufferSize"></param> /// <param name="maxMessageSize"></param> /// <param name="maxConnections"></param> /// <exception cref="ArgumentNullException">socketService is null.</exception> /// <exception cref="ArgumentNullException">protocol is null.</exception> /// <exception cref="ArgumentOutOfRangeException">maxMessageSize</exception> /// <exception cref="ArgumentOutOfRangeException">maxConnections</exception> public SocketServer(IServerHandler handler, Protocol.IProtocol protocol, int socketBufferSize, int messageBufferSize, int maxMessageSize, int maxConnections) : base(socketBufferSize, messageBufferSize) { if (handler == null) throw new ArgumentNullException("handler"); if (protocol == null) throw new ArgumentNullException("protocol"); if (maxMessageSize < 1) throw new ArgumentOutOfRangeException("maxMessageSize"); if (maxConnections < 1) throw new ArgumentOutOfRangeException("maxConnections"); this._handler = handler; this._protocol = protocol; this._maxMessageSize = maxMessageSize; this._maxConnections = maxConnections; }
public static async Task WriteServerInfo(this IServerHandler serverHandler, IDiscordClient client) { var channel = await client.GetChannelAsync(serverHandler.ServerInfoChannel) as ITextChannel; var messages = (await channel.GetMessagesAsync().FlattenAsync()).ToList(); var servers = serverHandler.GetServers(); if (servers.Count < messages.Count() && messages.Any(m => (DateTimeOffset.UtcNow - m.Timestamp).TotalDays > 14)) { //Recreate channel because discord does not allow deletion of messages older then 2 weeks var guild = channel.Guild; await channel.DeleteAsync(); channel = await guild.CreateTextChannelAsync(channel.Name, p => p.CategoryId = channel.CategoryId); messages.Clear(); } else { var messagesToDelete = messages.Skip(servers.Count); await channel.DeleteMessagesAsync(messagesToDelete); messages = messages.Take(servers.Count).ToList(); } for (int i = 0; i < servers.Count; i++) { var server = servers[i]; var embed = await BuildServerInfoEmbed(server, client); var message = messages.ElementAtOrDefault(i); if (message != null) { await(message as RestUserMessage).ModifyAsync(m => m.Embed = embed); } else { await channel.SendMessageAsync(null, embed : embed); } } }
/// <summary> /// 使用默认配置参数的构造函数 /// </summary> /// <param name="handler"></param> public SocketServer(IServerHandler handler, IEncoder encoder, IDecoder decoder) : base(DefaultConfigure.SocketBufferSize, DefaultConfigure.MessageBufferSize) { if (handler == null) { throw new ArgumentNullException("handler"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } if (decoder == null) { throw new ArgumentNullException("decoder"); } this._handler = handler; this._protocol = new DefaultBinaryProtocol(); this._encoder = encoder; this._decoder = decoder; this._maxMessageSize = DefaultConfigure.MaxMessageSize; this._maxConnections = DefaultConfigure.MaxConnections; }
public Task <ServerResponse> ProcessRequest(ServerRequest request) { // The runtime is a server module, which is logically at the end of the module // pipeline (i.e. doesn't wrap another module), and it is responsible for executing // the handler associated with the current route, or generating a not found response. IServerHandler handler = null; ServerRoute route = request.Route; if (route != null) { handler = route.Handler; } if (handler != null) { return(handler.ProcessRequest(request)); } else { return(Deferred.Create <ServerResponse>(ServerResponse.NotFound).Task); } }
public static void Execute(IServerHandler handler, BitBuffer buffer, ushort commandCount) { for (int i = 0; i < commandCount; i++) { var commandId = buffer.ReadUShort(); switch (commandId) { case 0: { Logger.I.Log("ServerCommandExecutor", "Executing ClientChatMessageCommand"); var c = new ClientChatMessageCommand(); c.Deserialize(buffer); handler.HandleChatMessageCommand(ref c); break; } case 1: { Logger.I.Log("ServerCommandExecutor", "Executing ClientRequestCharacterCommand"); var c = new ClientRequestCharacterCommand(); c.Deserialize(buffer); handler.HandleRequestCharacterCommand(ref c); break; } case 2: { Logger.I.Log("ServerCommandExecutor", "Executing ClientSetTickrateCommand"); var c = new ClientSetTickrateCommand(); c.Deserialize(buffer); handler.HandleSetTickrateCommand(ref c); break; } } } }
public void AddRoute(string route, IServerHandler handler) { }
public override void Configure(IApplicationBuilder appBuilder, ILifetimeScope lifetimeScope, IServerHandler serverHandler, ISerialize serialize) { base.Configure(appBuilder, lifetimeScope, serverHandler, serialize); ActorServiceFactory.UseActorService(appBuilder, lifetimeScope); }
/// <summary> /// Initialize new client /// </summary> /// <param name="port">Port to connect to</param> /// <param name="serverHandler">Instance of server handler interface</param> public Client(int port, IServerHandler serverHandler) : this(IPAddress.Loopback, port, serverHandler) { }
public FlightPlansController(APIContext context, IServerHandler handler) { _context = context; _handlerContext = handler; }
public virtual void Configure(IApplicationBuilder appBuilder, ILifetimeScope lifetimeScope, IServerHandler serverHandler, ISerialize serialize) { if (DaprConfig.GetCurrent().UseStaticFiles) { appBuilder.UseStaticFiles(); } if (DaprConfig.GetCurrent().UseCors) { appBuilder.UseCors(x => x.SetIsOriginAllowed(_ => true).AllowAnyHeader().AllowAnyMethod().AllowCredentials()); } serverHandler.BuildHandler(appBuilder, serialize); }
public DotNettyServerHandler(IServerHandler handler) { this.handler = handler; }
public virtual void Configure(IApplicationBuilder appBuilder, ILifetimeScope lifetimeScope, IServerHandler serverHandler, ISerialize serialize) { if (DaprConfig.GetCurrent().UseStaticFiles) { appBuilder.UseStaticFiles(); } serverHandler.BuildHandler(appBuilder, serialize); }
public ServerCommands(ILogger <ServerCommands> logger, IServerHandler serverHandler) { _logger = logger; _serverHandler = serverHandler; }