Exemple #1
0
        /* 서버 연결 해제 */
        public void Disconnect()
        {
            if (!_isConnect)
            {
                return;
            }
            _isConnect = false;
            Quit quit = new Quit();

            quit.Type = (int)PacketType.QUIT;
            Packet.Serialize(quit).CopyTo(_sendBuffer, 0);
            Send();
            _client.Close();
            _networkstream.Close();
            _thClient.Abort();

            _isLogin            = false;
            btnLogin.Text       = "로그인";
            btnLogin.ForeColor  = Color.Black;
            picHome.BackColor   = System.Drawing.SystemColors.Control;
            pnlHome.Visible     = false;
            picSearch.BackColor = System.Drawing.SystemColors.Control;
            pnlSearch.Visible   = false;
            picUpload.BackColor = System.Drawing.SystemColors.Control;
            pnlUpload.Visible   = false;
            picMypage.BackColor = System.Drawing.SystemColors.Control;
            pnlMypage.Visible   = false;
        }
Exemple #2
0
        private void pictureBoxSerach_Click(object sender, EventArgs e)
        {
            pictureBoxSerach.BackColor = SystemColors.ActiveCaption;
            pictureBoxMypage.BackColor = SystemColors.Control;
            pictureBoxUpload.BackColor = SystemColors.Control;
            pictureBoxHome.BackColor   = SystemColors.Control;

            panelUpload.Visible = false;
            panelHome.Visible   = false;
            panelMypage.Visible = false;
            panelSearch.Visible = true;
            if (!this.m_bConnect)
            {
                return;
            }
            Search searchClass = new Search();

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

            Packet.Serialize(searchClass).CopyTo(this.sendBuffer, 0);
            this.Send();
        }
Exemple #3
0
        private void Send() //Send 버튼을 눌렀을 때 thrsend 쓰레드 안에서 돌아갈 함수
        {
            try
            {
                while (ConnectedToServer)      //서버에 연결되어 있을 때
                {
                    buttonstream.Position = 0; //파일의 인덱스를 맨앞으로 이동시키고

                    FileInfo fi = new FileInfo(openFileDialog.FileName);

                    Fp = new FilePacket();

                    Fp.FileName = fi.Name;                                                         //파일의 경로를 생각한 짧은 경로를 얻어오기위해 FileInfo 사용
                    Fp.FileSize = fi.Length;                                                       //파일의 길이를 FileSize로 입력

                    Invoke(new MethodInvoker(delegate()                                            //Control을 건드리는 부분 --> Invoke 사용
                    {
                        ProgressBar.Minimum = 0;                                                   // 초기값 0
                        ProgressBar.Maximum = (int)(buttonstream.Length / Fp.FileData.Length) + 1; //보내야 하는 횟수
                        ProgressBar.Value   = 0;                                                   // 현재 값 0
                    }
                                             ));
                    for (int i = 0; i < (int)(buttonstream.Length / Fp.FileData.Length) + 1; i++)
                    {                                                          //파일의 크기를 버퍼의 크기로 나누고 나머지부분 전송을 위해 + 1번만큼 더 전송함
                        buttonstream.Read(Fp.FileData, 0, Fp.FileData.Length); //파일을 버퍼에 읽어와서
                        Fp.Type = 0;                                           //보통의 파일 전송 타입
                        Packet.Serialize(Fp).CopyTo(this.SendBuffer, 0);       //SendBuffer로 Serialize
                        NetStream.Write(SendBuffer, 0, SendBuffer.Length);     //네트워크 스트림에 쓴다
                        NetStream.Flush();                                     //보낸다

                        ClearBuffer(SendBuffer);                               //SendBuffer의 모든 index를 0으로 초기화

                        Invoke(new MethodInvoker(delegate()                    //Control을 건드리는 부분
                        {
                            ProgressBar.Value++;                               //Value를 증가시킴(Progressbar 수치 증가)
                        }
                                                 ));
                    }
                    //파일 전송 끝

                    buttonstream.Dispose();
                    buttonstream.Close();               //
                    FileTextBox.Clear();                //파일스트림을 닫아주고, 파일경로 텍스트박스 초기화

                    Invoke(new MethodInvoker(delegate() //컨트롤을 건드리는 부분
                    {
                        ListViewItem item = new ListViewItem(new string[] { fi.Name, fi.Length.ToString() });
                        listView.Items.Add(item);           //전송을 완료하면 서버의 경로에 이 파일도 저장되므로
                    }
                                             ));

                    threader = new Thread(new ThreadStart(Receive)); //Abort되었던 쓰레드를 다시 생성해줌
                    threader.Start();                                //시작
                    thrsender.Abort();                               //전송 쓰레드 Abort
                }
            }
            catch
            {//쓰레드가 중단되었습니다. 같은 무시할 수 있는 오류를 깔끔히 처리하기 위해서 비워둠
            }
        }
Exemple #4
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (txtPicturePath.Text == "" || picUploadPicture.ImageLocation == "")
            {
                MessageBox.Show("업로드할 사진을 선택하세요.");
            }
            else
            {
                Post post = new Post();
                post.Type   = (int)PacketType.POST;
                post._image = picUploadPicture.Image.Clone();
                post._text  = txtUploadText.Text;

                try
                {
                    Packet.Serialize(post).CopyTo(_sendBuffer, 0);
                    Send();
                }
                catch
                {
                    MessageBox.Show("파일 용량이 너무 큽니다. (512KB 이하)");
                }
                _isNew = true;
            }
        }
Exemple #5
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            m_Ip   = IPAddress.Parse("127.0.0.1");
            m_Port = 2222;

            m_Client = new TcpClient();
            try {
                m_Client.Connect(m_Ip, m_Port);
                m_bConnect = true;
            } catch {
                m_bConnect = false;
                MessageBox.Show("서버와 연결이 되지 않았습니다", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            m_Stream = m_Client.GetStream();
            if (!this.m_bConnect)
            {
                return;
            }

            Login login = new Login();

            login.Type = (int)PacketType.로그인;
            login.id   = txtLoginID.Text;
            login.pw   = txtLoginPW.Text;

            Packet.Serialize(login).CopyTo(this.sendBuffer, 0);
            this.Send();
            pnlWaitScreen.Visible = true;
            //this.Receive();
        }
Exemple #6
0
        public void Disconnect()
        {
            if (btnServerConnect.Text == "서버연결")
            {
                return;
            }

            btnServerConnect.Text      = "서버연결";
            btnServerConnect.ForeColor = Color.Black;


            if (!m_Client.Connected)
            {
                return;                      //이미 서버가 꺼져있다면 return;
            }
            try
            {
                if (DEBUGGING)
                {
                    Messenger ms = new Messenger("@[+]Disconnect[-]");
                    ms.Type = (int)PacketType.MESSAGE;//INIT 패킷
                    Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                    Send();
                }

                //서버에도 연결을 끊었다는 신호를 보내주어야 한다.
                Packet pk = new Packet();
                pk.Type = (int)PacketType.EXIT;
                Packet.Serialize(pk).CopyTo(this.sendBuffer, 0);
                Send();
            }
            catch (Exception e)
            {
                txtPort.Text = e.StackTrace;
                //서버쪽에서 연결을 해제함.
            }

            try
            {
                m_bConnect = false;
                lvwFiles.Clear();
                trvDir.Nodes.Clear();
                m_Client.Close();
                m_Stream.Flush();
                m_Stream.Close();
            }
            catch (Exception e)
            {
                txtIP.Text = e.StackTrace;
            }
        }
Exemple #7
0
        private void listview_dc(object sender, EventArgs e)
        {
            Packet packet2 = new Packet();

            packet2.type     = 1;
            packet2.filename = listView1.FocusedItem.Text;
            Packet.Serialize(packet2).CopyTo(this.sendBuffer, 0);
            this.m_NetStream.Write(this.sendBuffer, 0, this.sendBuffer.Length);
            this.m_NetStream.Flush();
            for (int i = 0; i < 1024 * 5; i++)
            {
                this.sendBuffer[i] = 0;
            }
        }
Exemple #8
0
 private void Form1_Closed(object sender, FormClosedEventArgs e)
 {
     if (btn_connect.Text == "Disconnect")
     {
         Packet packet4 = new Packet();
         packet4.type = 999;
         Packet.Serialize(packet4).CopyTo(this.sendBuffer, 0);
         m_NetStream.Write(this.sendBuffer, 0, this.sendBuffer.Length);
         m_NetStream.Flush();
         client.Close();
         m_NetStream.Close();
         m_thread.Abort();
     }
 }
Exemple #9
0
        private void btnJoin_Click(object sender, EventArgs e)
        {
            if (!_isConnect)
            {
                return;
            }

            Join join = new Join();

            join.Type      = (int)PacketType.JOIN;
            join._id       = txtID.Text;
            join._password = txtPassword.Text;

            Packet.Serialize(join).CopyTo(_sendBuffer, 0);
            Send();
        }
Exemple #10
0
        private void buttonLogIn_Click(object sender, EventArgs e)
        {
            if (!this.m_bConnect)
            {
                return;
            }

            Login login = new Login();

            login.Type          = (int)PacketType.로그인;
            login.m_strID       = this.textBoxID.Text;
            login.m_strPassword = this.textBoxPassword.Text;

            Packet.Serialize(login).CopyTo(this.sendBuffer, 0);
            this.Send();
        }
Exemple #11
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (btnLogin.Text == "로그인")
            {
                if (!_isConnect)
                {
                    return;
                }

                Login login = new Login();
                login.Type      = (int)PacketType.LOGIN;
                login._id       = txtID.Text;
                login._password = txtPassword.Text;
                _myPost         = new List <Post>();

                Packet.Serialize(login).CopyTo(_sendBuffer, 0);
                Send();
            }
            else
            {
                if (!_isConnect)
                {
                    return;
                }

                _isLogin    = false;
                _postnum    = 0;
                _memberList = null;
                _members    = null;
                lstSearch.Items.Clear();
                _myPost.Clear();

                btnLogin.Text      = "로그인";
                btnLogin.ForeColor = Color.Black;

                picHome.BackColor   = System.Drawing.SystemColors.Control;
                pnlHome.Visible     = false;
                picSearch.BackColor = System.Drawing.SystemColors.Control;
                pnlSearch.Visible   = false;
                picUpload.BackColor = System.Drawing.SystemColors.Control;
                pnlUpload.Visible   = false;
                picMypage.BackColor = System.Drawing.SystemColors.Control;
                pnlMypage.Visible   = false;
            }
        }
Exemple #12
0
        private void trvDir_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            Messenger mes = new Messenger("BeforeExpand...");

            mes.Type = (int)PacketType.MESSAGE;
            Packet.Serialize(mes).CopyTo(this.sendBuffer, 0);
            Send();

            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[+]TreeBeforeExpand");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }

            string path = e.Node.FullPath;

            File_Info fi = new File_Info(path);//해당 path의 하위 디렉토리들을 돌며 하위 디렉토리를 얻는다.

            fi.Type = (int)PacketType.FILE_INFO;
            Packet.Serialize(fi).CopyTo(this.sendBuffer, 0);
            Send();

            m_Stream.Read(readBuffer, 0, 1024 * 4);
            File_Info fInfo = (File_Info)Packet.Desserialize(readBuffer);//Desserialize

            TreeNode node;

            e.Node.Nodes.Clear();

            foreach (DirectoryInfo dis in fInfo.diArray)
            {
                node = e.Node.Nodes.Add(dis.Name);
                setPlus(node, fInfo.diArray.Length);
            }

            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[-]TreeBeforeExpand");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }
        }
Exemple #13
0
        private void listView_DoubleClick(object sender, EventArgs e) //리스트뷰 아이템을 더블클릭했을 때
        {
            if (thrsender.IsAlive)                                    //보내는 쓰레드가 살아있다면(보내는중이라면)
            {
                MessageBox.Show("Uploading...............");          //메시지 출력
                return;
            }

            Rq      = new Request(); //요청을 보내는 클래스인 Rq 인스턴스 생성
            Rq.Type = 2;             //타입도 요청으로 바꾸고
            ListViewItem item = listView.FocusedItem;

            Rq.FileName = item.SubItems[0].Text;               //선택된 파일의 이름을 클래스에 저장
            Packet.Serialize(Rq).CopyTo(this.SendBuffer, 0);   //Serialize해서 SendBuffer에 저장
            NetStream.Write(SendBuffer, 0, SendBuffer.Length); //네트워크 스트림에 씀
            NetStream.Flush();                                 //서버로 요청을 보냄
            ClearBuffer(SendBuffer);                           //버퍼를 초기화시킴
        }
Exemple #14
0
        private async void ProcessARQ(byte[] buffer)
        {
            var ARQPacket = await Packet.Serialize(buffer);

            Packet LostPacket;

            SentPackets.TryGetValue(ARQPacket.SequenceNumber, out LostPacket);

            if (LostPacket != null)
            {
                var PacketToSend = new Packet(Packet.Type.ARQResponse, ID, InterfaceID, Packet.Key, LostPacket.Data, LostPacket.RTT, LostPacket.SequenceNumber);

                await Send(PacketToSend);

                Console.WriteLine("QRQ");
            }

            //SentPackets.Remove(ARQPacket.SequenceNumber);
        }
Exemple #15
0
        private void trvDir_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[+]TreeBeforeSelect");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(sendBuffer, 0);
                Send();
            }

            SetListView(e.Node.FullPath);

            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[-]TreeBeforeSelect");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(sendBuffer, 0);
                Send();
            }
        }
Exemple #16
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 + "이걸 보내줘야되네");
            //패킷 수신 해줘야겠네
        }
Exemple #17
0
        public void FirstInit()
        {
            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[+]FirstInit");
                ms.Type = (int)PacketType.MESSAGE;//INIT 패킷
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }
            //서버한테  초기화정보 요청
            Packet Init = new Packet();

            Init.Type = (int)PacketType.INIT;//INIT 패킷
            Packet.Serialize(Init).CopyTo(this.sendBuffer, 0);
            Send();

            int    bytes = m_Stream.Read(readBuffer, 0, 1024 * 4);
            string path  = Encoding.UTF8.GetString(readBuffer, 0, bytes);

            TreeNode root;

            root            = trvDir.Nodes.Add(path); //서버에 최초로 등록된 path를 받는다.
            root.ImageIndex = (int)TREE_IMAGE.FOLDER;
            if (trvDir.SelectedNode == null)
            {
                trvDir.SelectedNode = root;
            }
            root.SelectedImageIndex = root.ImageIndex;
            root.Nodes.Add("");

            //SetListView(path);//BeforeSelectMethod(path);//해당 패스에 대한 dir 정보를 불러온다.

            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[-]FirstInit");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }
        }
Exemple #18
0
 private void btn_connect_Click(object sender, EventArgs e)
 {
     if (btn_connect.Text == "Connect")
     {
         btn_connect.ForeColor = Color.Red;
         btn_connect.Text      = "Disconnect";
         this.client           = new TcpClient();
         try
         {
             m_thread = new Thread(run);
             this.client.Connect(this.textBox_IP.Text, Int32.Parse(this.textBox_Port.Text));
             m_thread.Start();
         }
         catch
         {
             btn_connect.ForeColor = Color.Black;
             btn_connect.Text      = "Connect";
             MessageBox.Show("접속 에러");
             return;
         }
     }
     else
     {
         Packet packet4 = new Packet();
         packet4.type = 999;
         Packet.Serialize(packet4).CopyTo(this.sendBuffer, 0);
         m_NetStream.Write(this.sendBuffer, 0, this.sendBuffer.Length);
         m_NetStream.Flush();
         sendBuffer.Initialize();
         listView1.Items.Clear();
         client.Close();
         m_NetStream.Close();
         m_thread.Abort();
         m_thread = new Thread(run);
         btn_connect.ForeColor = Color.Black;
         btn_connect.Text      = "Connect";
         connection            = false;
     }
 }
Exemple #19
0
        private void setPlus(TreeNode node, int Dir_len)
        {
            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[+]setPlus");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }

            if (Dir_len > 0)//하위디렉토리 길이가 양수라면.
            {
                node.Nodes.Add("");
            }

            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[-]setPlus");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }
        }
Exemple #20
0
        public void SendPacket()
        {
            try
            {
                Thread.BeginCriticalRegion();
                byte[]   filedata = File.ReadAllBytes(textBox_File.Text);
                int      count    = (filedata.Length / (1024 * 4)) + 1;
                Packet   packet3  = new Packet();
                FileInfo fi       = new FileInfo(textBox_File.Text);
                packet3.type     = 2;
                packet3.filename = fi.Name;
                packet3.filesize = fi.Length;
                for (int i = 0; i < count; i++)
                {
                    if (i != (count - 1))
                    {
                        for (int k = i * (1024 * 4); k < (i * (1024 * 4)) + (1024 * 4); k++)
                        {
                            packet3.filedata[k - (i * 1024 * 4)] = filedata[k];
                        }
                    }

                    if (i == (count - 1))
                    {
                        packet3.filedata.Initialize();
                        for (int k = i * (1024 * 4); k < ((i * (1024 * 4)) + ((int)packet3.filesize % (1024 * 4))); k++)
                        {
                            packet3.filedata[k - (i * 1024 * 4)] = filedata[k];
                        }
                        filedata.Initialize();
                        listView1.Focus();
                    }
                    packet3.type = 2;
                    Packet.Serialize(packet3).CopyTo(this.sendBuffer, 0);
                    this.m_NetStream.Write(this.sendBuffer, 0, this.sendBuffer.Length);
                    this.m_NetStream.Flush();
                    pb_perform();
                    sendBuffer.Initialize();
                    packet3.filedata.Initialize();
                }
                packet3.type = 0;
                Packet.Serialize(packet3).CopyTo(this.sendBuffer, 0);
                m_NetStream.Write(this.sendBuffer, 0, this.sendBuffer.Length);
                m_NetStream.Flush();
                listView1.Enabled = true;
                listView1.Items.Clear();
                btn_Send.Enabled = true;
                Thread.EndCriticalRegion();
                send_Thread = new Thread(SendPacket);
            }
            catch
            {
                readBuffer.Initialize();
                sendBuffer.Initialize();
                listView1.Enabled = true;
                listView1.Items.Clear();
                btn_Send.Enabled      = true;
                btn_connect.ForeColor = Color.Black;
                btn_connect.Text      = "Connect";
                connection            = false;
                listView1.Items.Clear();
                client.Close();
                m_NetStream.Close();
                m_thread.Abort();
                m_thread = new Thread(run);
            }
        }
Exemple #21
0
        void SetListView(string path)
        {
            Messenger mes = new Messenger("BeforeSelect 데이터 요청...");

            mes.Type = (int)PacketType.MESSAGE;
            Packet.Serialize(mes).CopyTo(this.sendBuffer, 0);
            Send();

            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[+]ViewRight");
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }
            selectedPath = path;

            File_Info dInfo = new File_Info(path);

            dInfo.Type = (int)PacketType.FILE_INFO;
            Packet.Serialize(dInfo).CopyTo(this.sendBuffer, 0);
            Send();

            m_Stream.Read(readBuffer, 0, 1024 * 4);
            File_Info fInfo = (File_Info)Packet.Desserialize(readBuffer);//Desserialize

            if (DEBUGGING)
            {
                Messenger ms = new Messenger("SetListVeiwPath : " + fInfo.path);
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }
            //MessageBox.Show(path);

            ListViewItem item;

            try
            {
                lvwFiles.Items.Clear();

                foreach (DirectoryInfo di in fInfo.diArray)
                {
                    item = lvwFiles.Items.Add(di.Name);
                    item.SubItems.Add("");
                    item.SubItems.Add(di.LastWriteTime.ToString());
                    item.ImageIndex = (int)TREE_IMAGE.FOLDER;
                    item.Tag        = "D";
                }

                foreach (FileInfo fi in fInfo.fiArray)
                {
                    if (!files.ContainsKey(path + "\\" + fi.Name))
                    {
                        files.Add(path + "\\" + fi.Name, fi);//path에 대한 fileinfo
                    }
                    item = lvwFiles.Items.Add(fi.Name);
                    item.SubItems.Add(fi.Length.ToString());
                    item.SubItems.Add(fi.LastWriteTime.ToString());

                    if (fi.Extension == ".avi" || fi.Extension == ".mp4")
                    {
                        item.ImageIndex = (int)TREE_IMAGE.VEDIO;
                    }
                    else if (fi.Extension == ".jpg" || fi.Extension == ".png")
                    {
                        item.ImageIndex = (int)TREE_IMAGE.IMAGE;
                    }
                    else if (fi.Extension == ".mp3" || fi.Extension == ".wav")
                    {
                        item.ImageIndex = (int)TREE_IMAGE.MUSIC;
                    }
                    else if (fi.Extension == ".txt")
                    {
                        item.ImageIndex = (int)TREE_IMAGE.TEXT;
                    }
                    else
                    {
                        item.ImageIndex = (int)TREE_IMAGE.OTHER;
                    }

                    item.Tag     = "F";
                    selectedList = item;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (DEBUGGING)
            {
                Messenger ms = new Messenger("@[-]ViewRight");
                ms.Type = (int)PacketType.MESSAGE;//INIT 패킷
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
            }
        }
Exemple #22
0
        private void buttonUpload_Click(object sender, EventArgs e)
        {
            //textBoxUpload.Text;


            if (!this.m_bConnect)
            {
                return;
            }
            if (textBoxPicturepath.Text == "")
            {
                MessageBox.Show("사진을 선택해주세요");
                return;
            }

            Upload uploadClass = new Upload();

            uploadClass.Type      = (int)PacketType.업로드;
            uploadClass.m_strID   = this.textBoxID.Text;
            uploadClass.m_message = this.textBoxUpload.Text;
            //uploadClass.m_file = this.m_fileStream;
            uploadClass.m_filename = ohoh_filename;
            ohoh_filename          = "";
            uploadClass.m_byte     = ohoh_array;
            PictureBox pictureBox1 = new PictureBox();

            //pictureBox1.Location = new System.Drawing.Point(79, 40);
            pictureBox1.Name     = "pictureBox1";
            pictureBox1.Image    = Image.FromFile(textBoxPicturepath.Text);
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            panelImage.Controls.Add(pictureBox1);


            //panelImage.BackgroundImage = Image.FromFile(textBoxPicturepath.Text);
            labelPostCounting.Text = (Int32.Parse(labelPostCounting.Text) + 1).ToString();

            //searchClass.m_strPassword = this.textBoxPassword.Text;
            //MessageBox.Show("어디서 뒤졋지222");

            Packet.Serialize(uploadClass).CopyTo(this.sendBuffer, 0);
            this.Send();
            for (int i = 0; i < uploadClass.m_byte.Length; i++)
            {
                ohoh_array[i] = 0;
            }


            //MessageBox.Show("AAAA");

            //nRead = this.m_networkstream.Read(readBuffer, 0, 1024*1024 * 4);//여기서 멈춰있나
            MessageBox.Show("전송 완료!");
            //Packet packet = (Packet)Packet.Desserialize(this.readBuffer);//이거 까지 올려야되나
            //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);
            //                }
            //            }));
            //            break;
            //        }
            //}
        }
Exemple #23
0
        private void mnuDownload_Click(object sender, EventArgs e)
        {
            if (selectedList.Tag.ToString() == "D")
            {
                MessageBox.Show("폴더는 다운로드를 지원하지 않습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DownFile df = new DownFile();

            df.name       = selectedList.Text;
            df.ClientPath = txtPath.Text;
            df.ServerPath = selectedPath + "\\" + selectedList.Text;
            df.Type       = (int)PacketType.DOWNLOAD;
            Packet.Serialize(df).CopyTo(this.sendBuffer, 0);
            Send();

            FileInfo f = files[selectedPath + "\\" + selectedList.Text];

            FileStream   file = null;
            BinaryWriter bw   = null;

            try
            {
                // 파일 스트림 생성
                file = new FileStream(df.ClientPath + "\\" + df.name, FileMode.Create);
                bw   = new BinaryWriter(file);
                //파일이 이미 존재하는 경우 unAuto.... 예외발생
                byte[] bytesFileBuffer = new byte[f.Length];
                int    bytes           = m_Stream.Read(bytesFileBuffer, 0, (int)f.Length);
                bw.Write(bytesFileBuffer);
            }
            catch (UnauthorizedAccessException ex)
            {
                Messenger ms = new Messenger("파일 수신 접근권한거부 : " + ex.StackTrace);
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
                return;
            }
            catch (Exception ex)
            {
                Messenger ms = new Messenger("파일 수신 실패 : " + ex.Message);
                ms.Type = (int)PacketType.MESSAGE;
                Packet.Serialize(ms).CopyTo(this.sendBuffer, 0);
                Send();
                return;
            }
            finally
            {
                // 파일 스트림 닫기
                if (bw != null)
                {
                    bw.Close();
                }
                if (file != null)
                {
                    file.Close();
                }
            }

            Messenger ms2 = new Messenger(df.name + " 데이터 다운로드 완료...");

            ms2.Type = (int)PacketType.MESSAGE;
            Packet.Serialize(ms2).CopyTo(this.sendBuffer, 0);
            Send();
        }