예제 #1
0
        void btn_join_Clicked(object sender, EventArgs arg)
        {
            // 띄어쓰기 등등 체크해야함.
            if (tb_Password.Text != tb_chkPassword.Text)
            {
                MessageBox.Show("비밀번호 확인 다시하세요", "비번체크");
            }
            else
            {
                // 서버에 정보를 보낸후,

                TcpClient tc   = new TcpClient("127.0.0.1", 7000);
                string    msg  = tb_ID.Text + " " + tb_Password.Text;
                byte[]    bMsg = Encoding.Unicode.GetBytes(msg);
                TcpHeader head = new TcpHeader();
                head.mode    = 1;
                head.msgsize = (uint)szHeader + (uint)bMsg.Length;
                ByteField joinInfo = new ByteField(256);
                joinInfo.setHeader(head);
                joinInfo.ConcStrAfterHead(bMsg);

                NetworkStream stream = tc.GetStream();
                stream.Write(joinInfo.m_field, 0, joinInfo.m_size);



                int       cnt         = 0;
                ByteField msgFromServ = new ByteField(bytesize);
                // 헤더수신보장
                cnt += stream.Read(msgFromServ.m_field, 0, bytesize - cnt);
                while (cnt <= 8)
                {
                    cnt += stream.Read(msgFromServ.m_field, cnt, bytesize - cnt);
                }

                int msgze = (int)msgFromServ.getheader().msgsize;

                while (cnt <= msgze)
                {
                    cnt += stream.Read(msgFromServ.m_field, cnt, bytesize - cnt);
                }

                MessageBox.Show(msgFromServ.getMsgStr());


                tc.Close();
                stream.Close();
            }
            this.Dispose(true);
        }
예제 #2
0
        //loginclicked
        void btnLoginClicked(object sender, MouseEventArgs e)
        {
            TcpClient     tcpClient = new TcpClient(server, 7000);
            NetworkStream stream    = tcpClient.GetStream();
            string        id        = tbx_ID.Text;
            string        password  = tbx_password.Text;
            ByteField     loginmsg  = new ByteField(256);

            string    msg = id + " " + password;
            TcpHeader head;

            head.mode    = 2;
            head.msgsize = 0;
            loginmsg.setHeader(head);
            loginmsg.ConcStrAfterHead(msg);
            loginmsg.setHeadLenByIndex();

            stream.Write(loginmsg.m_field, 0, (int)loginmsg.getheader().msgsize);

            int       cnt         = 0;
            ByteField msgFromServ = new ByteField(256);

            cnt += stream.Read(msgFromServ.m_field, 0, 256 - cnt);
            while (cnt < 8)
            {
                cnt += stream.Read(msgFromServ.m_field, cnt, 256 - cnt);
            }

            if (msgFromServ.getheader().mode == 200)
            {
                // 로그인 시작
                Form client = new ProfileForm();
                ((ProfileForm)client).initData(tbx_ID.Text, tcpClient, msgFromServ.getMsgStr());

                client.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("아이디와비밀번호를 확인해주세요");
            }
        }