コード例 #1
0
        /// <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;
        }
コード例 #2
0
ファイル: SuiDaoServer.cs プロジェクト: luojinfang/FastTunnel
        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);
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
 public ChatHostedService(IOptions <ServerConfig> options, ServerOptions serverOptions, IServerHandler serverHandler, IUserRepository userRepository)
 {
     this.serverConfig   = options.Value;
     this.serverOptions  = serverOptions;
     this.serverHandler  = serverHandler;
     this.userRepository = userRepository;
 }
コード例 #5
0
        public static IServer CreateTcpServer(IServerHandler handler, IPacket packet)
        {
            TcpServer server = new TcpServer();

            server.Handler = handler;
            server.Packet  = packet;
            return(server);
        }
コード例 #6
0
        public static IServer CreateTcpServer(NetConfig config, IServerHandler handler, IPacket packet)
        {
            TcpServer server = new TcpServer(config);

            server.Handler = handler;
            server.Packet  = packet;
            return(server);
        }
コード例 #7
0
 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();
 }
コード例 #8
0
            public TcpConnection(Socket socket, IServerHandler <Type> handler)
            {
                this.socket  = socket;
                this.handler = handler;

                asyncReadCalback  = new AsyncCallback(ReadCallback);
                asyncSendCallback = new AsyncCallback(SendCallback);
            }
コード例 #9
0
ファイル: Client.cs プロジェクト: sxg133/collabtool-prototype
        /// <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();
        }
コード例 #10
0
ファイル: ServerFactory.cs プロジェクト: aslyr/BeetlexSample
        public static IServer CreateTcpServer(IServerHandler handler, IPacket packet, ServerOptions options = null)
        {
            TcpServer server = new TcpServer(options);

            server.Handler = handler;
            server.Packet  = packet;
            return(server);
        }
コード例 #11
0
 public void StopListening()
 {
     if (listeningTcpSocket != null)
     {
         listeningTcpSocket.Close();
         listeningTcpSocket = null;
     }
     handler = null;
 }
コード例 #12
0
 public void StopListening()
 {
     if (listeningClient != null)
     {
         listeningClient.Close();
         listeningClient = null;
     }
     handler = null;
     establishedConnections.Clear();
 }
コード例 #13
0
        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();
        }
コード例 #14
0
 /// <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;
 }
コード例 #15
0
        /// <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;
        }
コード例 #16
0
        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);
                }
            }
        }
コード例 #17
0
 /// <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;
 }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
    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;
            }
            }
        }
    }
コード例 #20
0
ファイル: ServerRouter.cs プロジェクト: nikhilk/simplecloud
 public void AddRoute(string route, IServerHandler handler)
 {
 }
コード例 #21
0
 public override void Configure(IApplicationBuilder appBuilder, ILifetimeScope lifetimeScope, IServerHandler serverHandler, ISerialize serialize)
 {
     base.Configure(appBuilder, lifetimeScope, serverHandler, serialize);
     ActorServiceFactory.UseActorService(appBuilder, lifetimeScope);
 }
コード例 #22
0
ファイル: Client.cs プロジェクト: sxg133/collabtool-prototype
 /// <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)
 {
 }
コード例 #23
0
ファイル: ServerRouter.cs プロジェクト: nikhilk/simplecloud
 public void AddRoute(string route, IServerHandler handler)
 {
 }
コード例 #24
0
 public FlightPlansController(APIContext context, IServerHandler handler)
 {
     _context        = context;
     _handlerContext = handler;
 }
コード例 #25
0
 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);
 }
コード例 #26
0
 public DotNettyServerHandler(IServerHandler handler)
 {
     this.handler = handler;
 }
コード例 #27
0
 public virtual void Configure(IApplicationBuilder appBuilder, ILifetimeScope lifetimeScope, IServerHandler serverHandler, ISerialize serialize)
 {
     if (DaprConfig.GetCurrent().UseStaticFiles)
     {
         appBuilder.UseStaticFiles();
     }
     serverHandler.BuildHandler(appBuilder, serialize);
 }
コード例 #28
0
 public ServerCommands(ILogger <ServerCommands> logger, IServerHandler serverHandler)
 {
     _logger        = logger;
     _serverHandler = serverHandler;
 }