Example #1
0
        public Client(string name, IPEndPoint iPEndPoint, Socket socket, Dictionary <IPEndPoint, string> connectedClients,
                      IStringMethods stringMethods, IUserMethods userMethods)
        {
            signalHandler += HandleConsoleSignal;
            SetSignalHandler(signalHandler, true);

            this.name          = name;
            ConnectedClients   = connectedClients;
            this.iPEndPoint    = iPEndPoint;
            this.socket        = socket;
            this.userMethods   = userMethods;
            this.stringMethods = stringMethods;
        }
Example #2
0
        public Client(IStringMethods stringMethods, IUserMethods userMethods)
        {
            signalHandler += HandleConsoleSignal;
            SetSignalHandler(signalHandler, true);

            ConnectedClients   = new Dictionary <IPEndPoint, string>();
            socket             = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.stringMethods = stringMethods;
            this.userMethods   = userMethods;

            iPEndPoint = null;
            bool isStarted = false;

            while (isStarted != true)
            {
                Console.Write("Input your port: ");
                int port = userMethods.ReadPort();

                try
                {
                    foreach (var iPAdress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                    {
                        if (iPAdress.AddressFamily == AddressFamily.InterNetwork)
                        {
                            iPEndPoint = new IPEndPoint(iPAdress, port);
                            break;
                        }
                    }

                    socket.Bind(iPEndPoint);
                    isStarted = true;
                }
                catch (Exception)
                {
                    Console.WriteLine("This port is already in use.");
                }
            }

            Console.Write("Input your name: ");
            name = userMethods.ReadName() + '(' + iPEndPoint.ToString() + ')';
            Console.Write("Your full name is ");
            Console.WriteLine(name);
            Console.WriteLine();
            this.userMethods.PrintUsingInformation();
            Console.WriteLine();
        }
Example #3
0
 public ProblemQ1(IStringMethods myStringMethods)
 {
     _stringMethods = myStringMethods;
 }
Example #4
0
 public UserMethods(IStringMethods stringMethods)
 {
     this.stringMethods = stringMethods;
 }
Example #5
0
 static StringExtensions()
 {
     _strMethods = new StringMethods();
 }
Example #6
0
 public DecimalMethods()
 {
     _stringMethods = new StringMethods();
 }
Example #7
0
 public Chat(IStringMethods stringMethods, IUserMethods userMethods)
 {
     this.stringMethods      = stringMethods;
     this.userMethods        = userMethods;
     ConnectedClientsHistory = new Dictionary <IPEndPoint, string>();
 }