Beispiel #1
0
        private void buttonJoin_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("어디서 뒤졋지111");

            if (!this.m_bConnect)
            {
                return;
            }
            Join joinClass = new Join();

            joinClass.Type          = (int)PacketType.회원가입;
            joinClass.m_strID       = this.textBoxID.Text;
            joinClass.m_strPassword = this.textBoxPassword.Text;
            //MessageBox.Show("어디서 뒤졋지222");

            Packet.Serialize(joinClass).CopyTo(this.sendBuffer, 0);
            this.Send();

            //MessageBox.Show(textBoxID.Text + "랑" + textBoxPassword.Text + "이걸 보내줘야되네");
            //패킷 수신 해줘야겠네
        }
Beispiel #2
0
        public void RUN()
        {
            CheckForIllegalCrossThreadCalls = false;    // cross thread false
            this.m_client = new TcpClient();


            try
            {
                //client = new TcpClient();
                IPAddress locAddr = IPAddress.Parse(textBoxIP.Text); int port = Int32.Parse(textBoxPort.Text);
                m_client.Connect(locAddr, port);
            }
            catch (SocketException se)
            {
                MessageBox.Show("서버 연결중에 오류 발생!");
                return;
            }
            buttonConnect.Text       = "Disconnect";//버튼 변경을 여기서 해주면 될까?
            buttonConnect.ForeColor  = Color.Red;
            textBoxID.ReadOnly       = false;
            textBoxPassword.ReadOnly = false;
            textBoxIP.ReadOnly       = true;
            textBoxPort.ReadOnly     = true;
            //textBox_PortNumber.ReadOnly = true;
            buttonLogIn.Enabled = true;
            buttonJoin.Enabled  = true;
            //                MessageBox.Show("여기는 오니?");
            this.m_bConnect      = true;
            this.m_networkstream = this.m_client.GetStream();
            int nRead = 0;

            while (this.m_bConnect)
            {
                nRead = 0;

                nRead = this.m_networkstream.Read(readBuffer, 0, 1024 * 1024 * 4);//여기서 멈춰있나


                Packet packet = (Packet)Packet.Desserialize(this.readBuffer);//이거 까지 올려야되나
                try
                {
                    switch ((int)packet.Type)
                    {
                    case (int)PacketType.조회:
                    {
                        this.m_searchClass = (Search)Packet.Desserialize(this.readBuffer);
                        this.Invoke(new MethodInvoker(delegate()
                            {
                                ListBoxSearch.Items.Clear();

                                foreach (string ohho in m_searchClass.m_list)
                                {
                                    ListBoxSearch.Items.Add(ohho);
                                }
                            }));
                        //MessageBox.Show("받았쪄");
                        break;
                    }

                    case (int)PacketType.로그인:    //정상 로그인
                    {
                        this.m_loginClass = (Login)Packet.Desserialize(this.readBuffer);
                        this.Invoke(new MethodInvoker(delegate()
                            {
                                if (m_loginClass.Data == 0)
                                {
                                    //MessageBox.Show("가입 성공");
                                    //errorClass.str = "이미 사용중인 ID입니다.";
                                    if (buttonLogIn.Text == "로그인")
                                    {
                                        buttonLogIn.ForeColor = Color.Red;
                                        buttonLogIn.Text      = "로그아웃";
                                    }
                                    else
                                    {
                                        buttonLogIn.ForeColor = Color.Black;
                                        buttonLogIn.Text      = "로그인";
                                    }
                                }
                                else
                                {
                                    MessageBox.Show(this.m_loginClass.str);
                                }
                            }));
                        break;
                    }

                    case (int)PacketType.회원가입:
                    {
                        this.m_joinClass = (Join)Packet.Desserialize(this.readBuffer);
                        this.Invoke(new MethodInvoker(delegate()
                            {
                                if (m_joinClass.Data == 1)
                                {
                                    MessageBox.Show(this.m_joinClass.str);
                                }


                                //MessageBox.Show("가입 성공");
                                //errorClass.str = "이미 사용중인 ID입니다.";
                            }));

                        break;
                    }
                    }
                }
                catch
                {
                    this.m_bConnect      = false;
                    this.m_networkstream = null;
                    MessageBox.Show("클라이언트 종료");
                    break;//오 이러니까 되는거 같다. 개꿀 또 안되네 뭐지
                }
            }
        }