Beispiel #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SntpMessageEventArgs" /> class.
        /// </summary>
        /// <param name="channel">Socket channel request is recived on.</param>
        /// <param name="data">Raw data received from socket.</param>
        public SntpMessageEventArgs(SocketChannel channel, SocketBuffer data)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }
            this.Channel = channel;

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            this.ChannelBuffer = data;

            try
            {
                // Parse the sntp message
                this.RequestMessage = new SntpMessage(data.Buffer);

                // log that the packet was successfully parsed
                logger.Debug("PACKET with channel id " + this.Channel.ChannelId.ToString() +
                             " successfully parsed from client endpoint " + this.Channel.RemoteEndpoint.ToString());
                logger.Debug(RequestMessage.ToString());
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error parsing message:" + ex.Message.ToString());
                // disconnect ?
                return;
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ClientConnectedEventArgs" /> class.
        /// </summary>
        /// <param name="socket">The channel.</param>
        public SocketEventArgs(Socket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            Channel       = new SocketChannel();
            ChannelBuffer = new SocketBuffer();
            Channel.Assign(socket);
        }
Beispiel #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ClientConnectedEventArgs" /> class.
        /// </summary>
        /// <param name="socket">The channel.</param>
        /// <param name="messageBuffer">The message buffer.</param>
        public ClientConnectedEventArgs(Socket socket, int messageBuffer)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            AllowConnect = true;

            Channel       = new SocketChannel();
            ChannelBuffer = new SocketBuffer(messageBuffer);
            Channel.Assign(socket);
        }
Beispiel #4
0
        private void OnClientConnect(object sender, ClientConnectedEventArgs args)
        {
            SocketBuffer channelBuffer = args.ChannelBuffer;

            if (channelBuffer != null &&
                args.Channel.IsConnected &&
                channelBuffer.BytesTransferred >= Constants.SNTP_MIN_MESSAGE_SIZE &&
                channelBuffer.BytesTransferred <= Constants.SNTP_MAX_MESSAGE_SIZE)
            {
                logger.Debug("PACKET request with channel id " +
                             args.Channel.ChannelId.ToString() +
                             " was received from " +
                             args.Channel.RemoteEndpoint.ToString() +
                             " and queued for processing...");

                SntpMessageEventArgs messageArgs = new SntpMessageEventArgs(args.Channel, args.ChannelBuffer);
                OnSntpMessageReceived(this, messageArgs);

                ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessRequest), messageArgs);
            }
        }
Beispiel #5
0
        /// <summary>
        ///     Send a new message to a connected socket.
        /// </summary>
        /// <param name="message">A message type Socket Buffer that contains the data to be sent.</param>
        public void Send(SocketBuffer message)
        {
            Stream sendMessage = new MemoryStream(message.Buffer);

            Send(sendMessage);
        }