示例#1
0
文件: Program.cs 项目: qhrrkfl2/KAKAO
        static void Main(string[] args)
        {
            TcpClient tc = new TcpClient("127.0.0.1", 7000);


            if (tc.Connected)
            {
                System.Console.WriteLine("켜짐");
            }

            NetworkStream st   = tc.GetStream();
            ByteField     file = new ByteField(256);

            file.ConcStrAfterHead("메세지를 보냄");
            file.setHeadFromField(3);

            st.Write(file.m_field, 0, (int)file.getheader().msgsize);
            System.Console.WriteLine("헤더 데이터 {0} {1}", file.getheader().mode, file.getheader().msgsize);
            st.Close();
            st.Dispose();
            tc.Close();
        }
示例#2
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);
        }
示例#3
0
        // background // 센드 블락킹으로 인한 수신 이펙트 막는거 방지를 위함.
        void sendMsgToServ()
        {
            while (true)
            {
                if (QueDataSendPend.Count != 0)
                {
                    string    msg     = QueDataSendPend.Dequeue();
                    ByteField sendMsg = new ByteField(256);
                    sendMsg.ConcStrAfterHead(msg);
                    sendMsg.setHeadFromField(300);

                    stream.Write(sendMsg.m_field, 0, (int)sendMsg.getheader().msgsize);
                }
            }
        }
示例#4
0
文件: Program.cs 项目: qhrrkfl2/KAKAO
        static void Main(string[] args)
        {
            TcpListener listen = new TcpListener(IPAddress.Any, 7000);

            listen.Start();
            ByteField     f1     = new ByteField(256);
            TcpClient     sock   = listen.AcceptTcpClient();
            NetworkStream stream = sock.GetStream();


            //  if (sock.Connected)
            //  {
            //      stream.Read(f1.m_field, 0, 8);
            //      int len = (int)f1.getheader().msgsize;
            //      stream.Read(f1.m_field, 8, len);
            //      Console.WriteLine("헤더데이터 {0} {1}", f1.getheader().mode, f1.getheader().msgsize);
            //      Console.WriteLine(f1.getMsgStr());
            //
            //
            //  }



            if (sock.Connected)
            {
                Console.WriteLine("정보받음");
                f1.ConcStrAfterHead("으베베");
                f1.setHeadFromField(200);
                stream.Write(f1.m_field, 0, 8);
            }

            //|head || SenderID" "MSG |
            while (true)
            {
                string        line = Console.ReadLine();
                StringBuilder sb   = new StringBuilder();
                sb.Append("tester");
                sb.Append(" ");
                sb.Append(line);
                line = sb.ToString();
                f1.ConcStrAfterHead(line);
                f1.setHeadFromField(300);
                stream.Write(f1.m_field, 0, (int)f1.getheader().msgsize);
            }

            // do thing you want.
        }
示例#5
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("아이디와비밀번호를 확인해주세요");
            }
        }
示例#6
0
文件: CButton.cs 项目: qhrrkfl2/KAKAO
        static public void GetMessage(ByteField field, NetworkStream stream)
        {
            int       bytesize    = 8;
            int       cnt         = 0;
            ByteField msgFromServ = field;

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

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

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