Exemple #1
0
            public void ClientFileSend(SocketMSG p_Msg, SockFileTransfer.DataPacket p_Packet, string pIPAddress)
            {
                new Thread(() =>
                {
                    try
                    {
                        //// Create a TCP / IP Socket
                        sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                        // //Connect to the server
                        sock.Connect(new IPEndPoint(IPAddress.Parse(pIPAddress), 12000));

                        // 데이터 전송
                        foreach (byte[] buff in p_Packet.Data.Values)
                        {
                            sock.Send(buff);
                        }
                    }
                    catch (SocketException se)
                    {
                        MessageBox.Show("SocketException = " + se.Message.ToString());
                        sock.Close();
                        sock.Dispose();
                    }
                }).Start();
            }
 public void OnSendData(MultiSockets.SocketMSG p_Msg, SockFileTransfer.DataPacket p_Packet)
 {
     lock (_lockSending)
     {
         Thread thread = new Thread(() => Run(p_Msg, p_Packet));
         thread.Start();
     }
 }
            private void Run(SocketMSG msg, SockFileTransfer.DataPacket Packet)
            {
                string sDataDesc = string.Empty;

                msg.sSender = CLIENTSOCK.LocalEndPoint.ToString();
                // 헤더/보낸사람/받는사람/파일이름,파일사이즈,[1024]로 나눠 받을 패킷 수
                sDataDesc = msg.sHeader.ToString() + '\x01' + msg.sSender + '\x01' + msg.sReceiver + '\x01' +
                            Packet.FileName + "/" + Packet.Size + "/" + Packet.PacketCnt + "/" + Packet.RemainPacket + '\x01';

                byte[] txtDataDesc = Encoding.UTF8.GetBytes(sDataDesc);

                // 파일 정보 전송
                CLIENTSOCK.Send(txtDataDesc);
            }
Exemple #4
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="p_Msg"></param>    데이터 정보 sHeader/sSender/sReceiver/sMsg
            /// <param name="p_Packet"></param> 보내는 데이터 FileName/PacketCnt/Size(length)/Data
            public void FileSend(SocketMSG p_Msg, SockFileTransfer.DataPacket p_Packet)
            {
                Socket socket;
                string sDataDesc = string.Empty;

                // 헤더/보낸사람/받는사람/파일이름,파일사이즈,[1024]로 나눠 받을 패킷 수
                sDataDesc = p_Msg.sHeader.ToString() + '\x01' + p_Msg.sSender + '\x01' + p_Msg.sReceiver + '\x01' +
                            p_Packet.FileName + "/" + p_Packet.Size + "/" + p_Packet.PacketCnt + "/" + p_Packet.RemainPacket + '\x01';
                for (int i = 0; i < lst_ConnectedClients.Count; i++)
                {
                    if (lst_ConnectedClients[i].RemoteEndPoint.ToString() == p_Msg.sReceiver)
                    {
                        socket = lst_ConnectedClients[i];
                        byte[] arr_DataDesc = Encoding.UTF8.GetBytes(sDataDesc);
                        // 파일 정보 전송
                        socket.Send(arr_DataDesc);
                        // 데이터 전송
                        foreach (byte[] buff in p_Packet.Data.Values)
                        {
                            socket.Send(buff);
                        }
                    }
                }
            }