Example #1
0
        private void AsyncHandleServImageAccept(IAsyncResult ar)
        {
            ImageAsyncServAcceptSocket = ImageAsyncServAcceptSocket.EndAccept(ar);

            IPEndPoint ipEPAcceptClient = (IPEndPoint)ImageAsyncServAcceptSocket.RemoteEndPoint;

            if (ImageAsyncServAcceptSocket.Connected)
                listBoxAsyncServ.Items.Add(ipEPAcceptClient.Address + "에서 이미지서버 접속함.");

            listBoxAsyncServ.SelectedIndex = listBoxAsyncServ.Items.Count - 1;
            AsyncServObject ao = new AsyncServObject(4096);
            ao.workSocket = ImageAsyncServAcceptSocket;

            ImageAsyncServAcceptSocket.BeginReceive(ao.buffer, 0, ao.buffer.Length, SocketFlags.None, asyncCbServImageReceive, ao);
        }
Example #2
0
        private void AsyncHandleServImageConnect(IAsyncResult ar)
        {
            Socket sock = (Socket)ar.AsyncState;
            try
            {
                sock.EndConnect(ar);

                if (sock.Connected)
                {
                    AsyncServObject ao = new AsyncServObject(4096);
                    ao.workSocket = sock;
                    listBoxAsyncServ.Items.Add("이미지서버 접속 완료");
                    listBoxAsyncServ.SelectedIndex = listBoxAsyncServ.Items.Count - 1;
                    sock.BeginReceive(ao.buffer, 0, ao.buffer.Length, SocketFlags.None, asyncCbServImageReceive, ao);
                }
                else
                {
                    sock.Close();
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }
Example #3
0
        private void AsyncHandleServAccept(IAsyncResult ar)
        {
            socketAyncServerMain = socketAyncServerMain.EndAccept(ar);

            IPEndPoint ipEPAcceptClient = (IPEndPoint)socketAyncServerMain.RemoteEndPoint;
            listBoxAsyncServ.Items.Add(ipEPAcceptClient.Address + " 접속.");
            listBoxAsyncServ.SelectedIndex = listBoxAsyncServ.Items.Count - 1;
            buttonAsyncServSend.Enabled = true;
            buttonAsyncServFileSend.Enabled = true;
            buttonAsyncServSendPicture.Enabled = true;

            AsyncServObject ao = new AsyncServObject(4096);
            ao.workSocket = socketAyncServerMain;

            socketAyncServerMain.BeginReceive(ao.buffer, 0, ao.buffer.Length, SocketFlags.None, asyncCbServrecv, ao);
        }
Example #4
0
        public void AsyncServSendImage()
        {
            byte[] btImage = msPictureAsyncServ.ToArray();
            AsyncServObject ao2 = new AsyncServObject(1);

            ao2.buffer = btImage;
            Thread.Sleep(100);
            ImageAsyncServAcceptSocket.Send(ao2.buffer);
            //if (ImageAsyncServAcceptSocket.Connected)
            //{
            //    ao2.workSocket = ImageAsyncServAcceptSocket;
            //    ImageAsyncServAcceptSocket.BeginSend(ao2.buffer, 0, ao2.buffer.Length, SocketFlags.None, asyncCbServImageSend, ao2);
            //}
            //else
            //{
            //    listBoxAsyncServ.Items.Add("재시도중...");
            //    AsyncServSendImage();
            //}
            buttonAsyncServSendPicture.Enabled = true;
        }
Example #5
0
        private void buttonAsyncServSend_Click(object sender, EventArgs e)
        {
            AsyncServObject ao = new AsyncServObject(1);

            ao.buffer = Encoding.UTF8.GetBytes("서버(비동기) : " + textBoxAsyncServSend.Text);

            textBoxAsyncServSend.Text = "";
            ao.workSocket = socketAyncServerMain;
            socketAyncServerMain.BeginSend(ao.buffer, 0, ao.buffer.Length, SocketFlags.None, asyncCbServSend, ao);
        }
Example #6
0
        private void buttonAsyncServSendPicture_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "이미지|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.psd";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBoxAsyncServ.Image = Bitmap.FromFile(openFileDialog1.FileName);
                if (msPictureAsyncServ != null)
                {
                    msPictureAsyncServ.Close();
                    msPictureAsyncServ.Dispose();
                }
                msPictureAsyncServ = new MemoryStream();
                pictureBoxAsyncServ.Image.Save(msPictureAsyncServ, System.Drawing.Imaging.ImageFormat.Png);

                AsyncServObject ao = new AsyncServObject(1);
                ao.buffer = Encoding.UTF8.GetBytes("ImageSend/" + msPictureAsyncServ.Length + "/");

                ao.workSocket = socketAyncServerMain;

                if (ImageAsyncServAcceptSocket != null)
                {
                    if (!ImageAsyncServAcceptSocket.IsBound)
                    {
                        asyncCbServImageAccept = new AsyncCallback(AsyncHandleServImageAccept);
                        asyncCbServImageSend = new AsyncCallback(AsyncHandleServImageSend);
                        asyncCbServImageReceive = new AsyncCallback(AsyncHandleServImageReceive);

                        ImageAsyncServAcceptSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        ImageAsyncServAcceptSocket.Bind(new IPEndPoint(IPAddress.Parse(labelAsyncServ2.Text), 7878));
                        ImageAsyncServAcceptSocket.Listen(5);
                        ImageAsyncServAcceptSocket.BeginAccept(asyncCbServImageAccept, null);
                    }
                }
                else
                {
                    asyncCbServImageAccept = new AsyncCallback(AsyncHandleServImageAccept);
                    asyncCbServImageSend = new AsyncCallback(AsyncHandleServImageSend);
                    asyncCbServImageReceive = new AsyncCallback(AsyncHandleServImageReceive);

                    ImageAsyncServAcceptSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    ImageAsyncServAcceptSocket.Bind(new IPEndPoint(IPAddress.Parse(labelAsyncServ2.Text), 7878));
                    ImageAsyncServAcceptSocket.Listen(5);
                    ImageAsyncServAcceptSocket.BeginAccept(asyncCbServImageAccept, null);
                }
                socketAyncServerMain.BeginSend(ao.buffer, 0, ao.buffer.Length, SocketFlags.None, asyncCbServSend, ao);
                buttonAsyncServSendPicture.Enabled = false;
                openFileDialog1.Dispose();
            }
            else
            {
                openFileDialog1.Dispose();
            }
        }
Example #7
0
        private void buttonAsyncServFileSend_Click(object sender, EventArgs e)
        {
            AsyncServObject ao = new AsyncServObject(1);
            ao.buffer = Encoding.UTF8.GetBytes("AsyncFileTrans/");
            ao.workSocket = socketAyncServerMain;

            if (fileWorkServAccpetSocket != null)
            {
                if (!fileWorkServAccpetSocket.IsBound)
                {
                    asyncCbServFileAccept = new AsyncCallback(AsyncHandleServFileAccept);
                    asyncCbServFileSend = new AsyncCallback(AsyncHandleServFileSend);
                    asyncCbServFileReceive = new AsyncCallback(AsyncHandleServFileRecv);

                    fileWorkServAccpetSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    fileWorkServAccpetSocket.Bind(new IPEndPoint(IPAddress.Parse(labelAsyncServ2.Text), 8890));
                    fileWorkServAccpetSocket.Listen(5);
                    fileWorkServAccpetSocket.BeginAccept(asyncCbServFileAccept, null);
                }
            }
            else
            {
                asyncCbServFileAccept = new AsyncCallback(AsyncHandleServFileAccept);
                asyncCbServFileSend = new AsyncCallback(AsyncHandleServFileSend);
                asyncCbServFileReceive = new AsyncCallback(AsyncHandleServFileRecv);

                fileWorkServAccpetSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                fileWorkServAccpetSocket.Bind(new IPEndPoint(IPAddress.Parse(labelAsyncServ2.Text), 8890));
                fileWorkServAccpetSocket.Listen(5);
                fileWorkServAccpetSocket.BeginAccept(asyncCbServFileAccept, null);
            }
            buttonAsyncServFileSend.Enabled = false;
            socketAyncServerMain.BeginSend(ao.buffer, 0, ao.buffer.Length, SocketFlags.None, asyncCbServSend, ao);
        }