Beispiel #1
0
        static string SingIn(Socket server)
        {
            string userName, password;
            string HelloTextBuf;

            while (true)
            {
                Console.Write("Input UserName Please : ");
                userName = Console.ReadLine();
                Console.Write("Input Password Please : ");
                password = Console.ReadLine();

                if (CheckEnglishNumber(userName) == false || CheckEnglishNumber(password) == false)
                {
                    continue;
                }

                HelloTextBuf = "SingIn" + ":" + userName + ":" + password;
                if (HelloTextBuf.Length > 512)
                {
                    continue;
                }
                server.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length)));
                break;
            }
            return(userName);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            IPEndPoint serverIPAddr = new IPEndPoint(IPAddress.Loopback, 12345);
            Socket     server       = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            server.Connect(serverIPAddr);

            string HelloTextBuf;

            byte[] data = new byte[512];

            Thread thread = new Thread(() => ReceiveData(server));

            thread.Start();

            //int receiveSize = server.Receive(data);
            //Console.WriteLine(Encoding.Default.GetString(data).Substring(0, receiveSize));

            while (true)
            {
                lock (thisLock)
                {
                    if (SingUpApproved == true)
                    {
                        break;
                    }
                }
            }

            while (true)
            {
                HelloTextBuf = Console.ReadLine();
                if (HelloTextBuf == "end")
                {
                    break;
                }
                if (HelloTextBuf.Length > 512)
                {
                    continue;
                }
                server.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length)));
            }

            server.Close();
        }