Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("What's your name?");
            Client.name = Console.ReadLine();
            Client.Start();
            Console.WriteLine("Client started");
            Client.ConnectToServer();
            Console.WriteLine("Client Connected");

            string input;

            Console.Write(">");
            while ((input = Console.ReadLine()) != "exit")
            {
                string[] query = input.Split(" ");
                if (query[0].ToLower() == "udp")
                {
                    Client.SendMessage(input, (int)ClientPackets.UdpMessage);
                }
                else if (query[0].ToLower() == "tcp")
                {
                    Client.SendMessage(input, (int)ClientPackets.TcpIssuedCommand);
                }
                else
                {
                    Client.SendMessage(input, (int)ClientPackets.TcpIssuedCommand);
                }
                Console.Write(">");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Client client = new Client();

            client.ConnectToServer();
            client.SendMessage();
            client.GetMessage();
        }
Example #3
0
 static void Main(string[] args)
 {
     while (true)
     {
         Client client = new Client("127.0.0.1", 8001);
         client.ConnectToServer();
         client.SendRequest();
         client.ReadResponse();
         client.CloseConnection();
     }
 }
Example #4
0
        static void Main(string[] args)
        {
            //title of client
            Console.Title = "Client ...";
            //ip
            string myIp = "192.168.254.1";
            //port
            int port = 5000;
            //create new client
            Client client = new Client(myIp, port);

            //conenct to server
            client.ConnectToServer();
            Console.Write("Connected to server");
            Thread.Sleep(1000);
            Console.Clear();
            Console.Clear();
            //creat server thread
            client.serverData();
            try
            {
                string messageToServer   = "";
                string messageFromServer = "";
                //while client online
                while (client.clientStatus)
                {
                    Console.Write("Client: ");
                    messageToServer = Console.ReadLine();

                    //client send 0 character
                    if (messageToServer == "0")
                    {
                        client.clientStatus = false;
                        client.streamWriter.WriteLine("Bye");
                        client.streamWriter.Flush();
                    }
                    else//text != 0
                    {
                        client.streamWriter.WriteLine(messageToServer);
                        client.streamWriter.Flush();
                        messageFromServer = client.streamReader.ReadLine();
                        Console.WriteLine("Server : " + messageFromServer);
                    }
                }
            }
            catch
            {
                Console.WriteLine("Error from Server");
            }

            client.disconect();
        }
        static void Main(string[] args)
        {
            Client ThangClient = new Client();
            string response;

            Console.WriteLine("Connecting to server...");
            if (ThangClient.ConnectToServer(out response))
            {
                Console.WriteLine("Connected successfully");
                while (true)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("You: ");
                    string message = Console.ReadLine();
                    if (message.Equals("exit", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return;
                    }
                    if (!ThangClient.SendToServer(message, out response))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("** ERROR: " + response);
                        break;
                    }
                    Console.ForegroundColor = ConsoleColor.White;
                    if (ThangClient.ReceiveFromServer(out response))
                    {
                        Console.WriteLine("Server: " + response);
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("** ERROR: " + response);
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine(response);
            }
            Console.ReadKey();
        }
 static void Main(string[] args)
 {
     Client.ConnectToServer(IPAddress.Parse("172.16.5.201"), 8080);
 }
Example #7
0
        static void Main(string[] args)
        {
            RSA    rsa;
            string address;
            short  port;
            string msg;


            Client client;

            rsa = new RSA(1024);

            try
            {
                Thread rsaAsync = new Thread(rsa.GenerateKeys);

                rsaAsync.Start();

                Console.WriteLine("IP-Address to chosen server: ");
                address = Console.ReadLine();
                Console.WriteLine("Port: ");
                while (!Int16.TryParse(Console.ReadLine(), out port))
                {
                    Console.WriteLine("Please choose a port between 1 and 65 535");
                }

                if (rsaAsync.IsAlive) // Wait for keys to be generated before we connect to a server
                {
                    Console.WriteLine("Waiting for encryption to complete...");
                    rsaAsync.Join();
                }

                Console.WriteLine("Pkey: " + rsa.n);

                Console.WriteLine("Connecting...");

                client = new Client(address, port, rsa);
                client.ConnectToServer();

                while (true)
                {
                    msg = "";
                    Console.WriteLine("Send a message to the server: ");
                    msg = Console.ReadLine();

                    if (msg.ToLower().Equals("disconnect"))
                    {
                        Console.WriteLine("Disconnecting from the server...");
                        client.Disconnect();
                        break;
                    }

                    client.SendMessage(msg);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Catched error: " + e.Message);
            }

            Console.WriteLine("End of program... press any key to exit");
            Console.ReadKey();
        }