Exemple #1
0
 public TcpServer(IPAddress ip, int port, int maxCon, TcpServerMode mode)
 {
     mMode             = mode;
     mIP               = ip;
     myPort            = port;
     mMaxConnection    = maxCon;
     msgs              = new Queue <List <string> >();
     clientSockets     = new List <Socket>();
     clientDict        = new Dictionary <Socket, int>();
     clientLinked      = new List <bool>();
     linkedClientNames = new ObservableCollection <NameData>();
 }
Exemple #2
0
        /// <summary>
        /// Parse the arguments and starts the show
        /// </summary>
        /// <param name="arguments">Commandline arguments</param>
        /// <returns>False if show can not start</returns>
        private bool DoWork(Arguments arguments)
        {
            IEchoMode mainMode;

            // Parse protocol
            var  strProtocol = arguments.Get("/p", string.Empty).ToLower();
            bool isProtocolUdp;

            switch (strProtocol)
            {
            case "udp":
                isProtocolUdp = true;
                break;

            case "tcp":
                isProtocolUdp = false;
                break;

            default:
                return(false);
            }

            // Should we run server mode
            if (arguments.Exists("/s"))
            {
                // UDP server or TCP mode
                if (isProtocolUdp)
                {
                    mainMode = new UdpServerMode(arguments);
                }
                else
                {
                    mainMode = new TcpServerMode(arguments);
                }
            }
            // or client mode
            else if (!string.IsNullOrEmpty(arguments.FirstArgument) && !arguments.FirstArgument.StartsWith("/"))
            {
                // UDP client or TCP mode
                if (isProtocolUdp)
                {
                    mainMode = new UdpClientMode(arguments);
                }
                else
                {
                    mainMode = new TcpClientMode(arguments);
                }
            }
            // no no, read the help
            else
            {
                return(false);
            }

            if (mainMode.ParseArguments())
            {
                mainMode.Run();
            }
            else
            {
                return(false);
            }

            return(true);
        }
 public TcpServerSettings()
 {
     ServerPort = 48157;
     Mode = TcpServerMode.Write;
 }