/// <summary> /// Accept the new client and store it in memory. /// </summary> /// <param name="AsyncEvent">The <see cref="SocketAsyncEventArgs"/> instance containing the event data.</param> private static void ProcessAccept(SocketAsyncEventArgs AsyncEvent) { if (AsyncEvent.AcceptSocket.Connected) { string IpAddress = ((IPEndPoint)AsyncEvent.AcceptSocket.RemoteEndPoint).Address.ToString(); if (IpAddress.StartsWith("192.168.")) { SocketAsyncEventArgs ReadEvent = NetworkTcp.ReadPool.Dequeue(); if (ReadEvent != null) { NetworkToken Token = new NetworkToken(ReadEvent, AsyncEvent.AcceptSocket); Device Device = new Device(Token); Devices.Add(Device); if (!Token.Socket.ReceiveAsync(ReadEvent)) { NetworkTcp.ProcessReceive(ReadEvent); } } else { Logging.Warning(typeof(NetworkTcp), "Server is full, new connections cannot be accepted."); } } } NetworkTcp.StartAccept(AsyncEvent); }
/// <summary> /// Initializes a new instance of the <see cref="NetworkManager"/> class. /// </summary> /// <param name="Device">The device.</param> public NetworkManager(Device Device) { this.Device = Device; this.Session = DateTime.UtcNow; this.LastMessage = DateTime.UtcNow; this.LastKeepAlive = DateTime.UtcNow; }
/// <summary> /// Handles the specified <see cref="Message"/>. /// </summary> /// <param name="Device">The device.</param> /// <param name="Message">The message.</param> /// <param name="Cancellation">The cancellation.</param> public static async Task Handle(Device Device, Message Message, CancellationToken Cancellation) { var DefaultMessage = (Message)Message; if (DefaultMessage == null) { throw new LogicException(typeof(DefaultHandler), nameof(DefaultMessage) + " == null at Handle(Device, Message, CancellationToken)."); } }
/// <summary> /// Sets the device. /// </summary> /// <param name="Device">The device.</param> public void SetDevice(Device Device) { this.Device = Device; this.Device.Token = this; }