Esempio n. 1
0
        private static void Client_Sent(object sender, EventArgs e)
        {
            TcpEventArgs args = (TcpEventArgs)e;

            if (args != null)
            {
                Console.WriteLine(string.Format("{0} sent \"{1}\" to {2}", args.LocalEndPoint, Encoding.ASCII.GetString((byte[])args.Data), args.RemoteEndPoint));
            }
        }
Esempio n. 2
0
        private static void Server_Received(object sender, EventArgs e)
        {
            TcpEventArgs args = (TcpEventArgs)e;

            if (args != null)
            {
                Console.WriteLine(string.Format("Server received \"{0}\" from {1}", args.Data, args.RemoteEndPoint));

                if (args.Data.Equals("send nudes"))
                {
                    Server server = (Server)sender;
                    server?.Send(args.RemoteEndPoint, "nudes");
                }
                else if (args.Data.Equals("send nudes to everyone"))
                {
                    Server server = (Server)sender;
                    server?.SendAll("nudes");
                }
            }
        }
Esempio n. 3
0
        private static void Client_Received(object sender, EventArgs e)
        {
            TcpEventArgs args = (TcpEventArgs)e;

            if (args != null)
            {
                Console.WriteLine(string.Format("{0} received \"{1}\" from {2}", args.LocalEndPoint, args.Data, args.RemoteEndPoint));

                if (args.Data.Equals("disconnect"))
                {
                    Client client = (Client)sender;
                    client?.Disconnect();
                    IsRunning = false;
                }
                else if (args.Data.Equals("hello"))
                {
                    Client client = (Client)sender;
                    client?.Send("hi!");
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Responds to the <see cref="Sent" /> event.
        /// </summary>
        /// <param name="args">
        /// The event data for the <see cref="Sent" /> event.
        /// </param>
        protected virtual void OnSent(TcpEventArgs args)
        {
            EventHandler handler = Sent;

            handler?.Invoke(this, args);
        }
Esempio n. 5
0
        /// <summary>
        /// Responds to the <see cref="Received" /> event.
        /// </summary>
        /// <param name="args">
        /// The event data for the <see cref="Received" /> event.
        /// </param>
        protected virtual void OnReceived(TcpEventArgs args)
        {
            EventHandler handler = Received;

            handler?.Invoke(this, args);
        }