Ejemplo n.º 1
0
        public string ReadLine()
        {
            string line = null;

            while (true)
            {
                byte[] bytes      = new byte[SocConst.MAX_STR_BUFFER_SIZE];
                int    bytesRec   = Receive(bytes);
                int    msgBufSize = 0;

                if (bytesRec > 0)
                {
                    line = SocUtils.GetMsgByPrefixLengthInfo(ref bytes, bytesRec, ref msgBufSize);
                }
                else
                {
                    break;
                }

                if (line.IndexOf("") > -1)
                {
                    break;
                }
            }
            return(line);
        }
Ejemplo n.º 2
0
        public void ReceiveMessage()
        {
            string line = "";

            try
            {
                mSender.ReceiveTimeout = 0;

                while (continueReceiving)
                {
                    byte[] bytes = new byte[SocConst.MAX_STR_BUFFER_SIZE];

                    int bytesRec = Receive(bytes);

                    //텍스트는 메시지가 잘려서 넘어오는 경우보다
                    //여러건이 연결해서 한꺼번에 오는 경우가 있어 이를 감안함.
                    int msgBufSize = 0;
                    while (bytesRec > 0)
                    {
                        //잘라서 처리
                        line = SocUtils.GetMsgByPrefixLengthInfo(ref bytes, bytesRec, ref msgBufSize);
                        if (line == null)
                        {
                            break;
                        }
                        if (msgBufSize > (bytesRec - 8))
                        {
                            break;                             //메시지가 잘린 경우
                        }
                        stateObj.Data = line;
                        line          = "";
                        OnMessageReceived(new SocStatusEventArgs(stateObj));
                    }

                    //if (bytesRec <= 0) {
                    //    if (line.Length > 0)
                    //    {
                    //        stateObj.Data = line;
                    //        line = "";
                    //        OnMessageReceived(new SocStatusEventArgs(stateObj));
                    //    }
                    //    continue;
                    //}

                    //if (line.IndexOf("") > -1 && line.Length > 0)
                    //{
                    //    stateObj.Data = line;
                    //    line = "";
                    //    OnMessageReceived(new SocStatusEventArgs(stateObj));
                    //}
                }
                continueReceiving = true;
            }
            catch (Exception ex)
            {
                Logger.error(ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public FtpClientManager(IPEndPoint ipAddress, string senderId, string fileName, long fileSize, string receiverId)
            : base(ipAddress.Address.ToString(), ipAddress.Port, SocUtils.GenerateFTPClientKey(senderId, SocUtils.GetFileName(fileName), fileSize, receiverId), SocConst.FTP_WAIT_TIMEOUT)
        {
//            string fileName)
//      {
            mFullPath = fileName;
            mFilePath = SocUtils.GetPath(fileName);
            mFileName = SocUtils.GetFileName(fileName);

            this.receiverId             = receiverId;
            mSocClient.ConnectionError += ProcessOnConnectionError;
        }
Ejemplo n.º 4
0
 public bool _NotifyFTPMsg(string msgRequest, IPEndPoint remoteIE, string senderId, string fileName, long fileSize, string receiverId)
 {
     tcpManager.Send(msgRequest);
     //다음 부분은 Sender부분으로 Receiver부분인 NotifyFTPReady, NotifyFTPReject에 대해선 필요없는 부분
     if (senderId.Equals(this.mKey))
     {
         string msgKey = SocUtils.GenerateFTPClientKey(senderId, SocUtils.GetFileName(fileName), fileSize, receiverId);
         if (mFileInfoMap.ContainsKey(msgKey))
         {
             mFileInfoMap.Remove(msgKey);
         }
         mFileInfoMap.Add(msgKey, new FTPSendObj(remoteIE, msgKey, fileName, fileSize, receiverId));
     }
     OnManagerStatusChanged(string.Format("파일정보 전송[{0}].", fileName));
     return(true);
 }
Ejemplo n.º 5
0
        public int Send(IPEndPoint iep, string msg)
        {
            Socket soc;

            lock (mClientTableLock) {
                if (mHtClientTable.ContainsKey(iep.ToString()))
                {
                    StateObject stateObj = mHtClientTable[iep.ToString()];
                    return(Send(stateObj.Soc, SocUtils.GetPrefixInfo(msg)) - 8);  //TEXT[msg length].... 8자리 감안
                }
                else
                {
                    StateObject stateObj = new StateObject();
                    stateObj.SocMessage = String.Format("{0} Send 대상연결이 없음 ", iep.ToString());
                    OnSocStatusChanged(new SocStatusEventArgs(stateObj));
                    return(SocCode.SOC_ERR_CODE);
                }
            }
        }
Ejemplo n.º 6
0
 public int Send(string msg)
 {
     // Encode the data string into a byte array.
     return(Send(SocUtils.GetPrefixInfo(msg)) - 8);  //TEXT[msg length].... 8자리 감안
 }
Ejemplo n.º 7
0
 public int Send(Socket soc, string msg)
 {
     return(Send(soc, SocUtils.GetPrefixInfo(msg)) - 8);  //TEXT[msg length].... 8자리 감안
 }
Ejemplo n.º 8
0
        public virtual void ReceiveMsg(object stObj)
        {
            byte[] bufferTxtRcv      = new byte[SocConst.MAX_STR_BUFFER_SIZE];
            byte[] bufferBinRcv      = new byte[SocConst.TEMP_BUFFER_SIZE];
            byte[] bufferTxtStateObj = new byte[SocConst.MAX_STR_BUFFER_SIZE];
            byte[] bufferBinStateObj = new byte[SocConst.MAX_BUFFER_SIZE];

            StateObject stateObj  = (StateObject)stObj;
            Socket      clientSoc = stateObj.Soc;

            int connectionCheckCnt = 0;

            try
            {
                while (true) // An incoming connection needs to be processed.
                {
                    int recv = 0;
                    stateObj.BufferSize = 0;
                    stateObj.Data       = "";
                    stateObj.SocMessage = "";
                    byte[] buffer;
                    if (stateObj.FtpStatus == FTPStatus.RECEIVE_STREAM)//파일수신
                    {
                        Array.Clear(bufferBinRcv, 0, bufferBinRcv.Length);
                        buffer = bufferBinRcv;
                        Array.Clear(bufferBinStateObj, 0, bufferBinStateObj.Length);
                        stateObj.Buffer = bufferBinStateObj;
                    }
                    else //일반메시지
                    {
                        Array.Clear(bufferTxtRcv, 0, bufferTxtRcv.Length);
                        buffer = bufferTxtRcv;
                        Array.Clear(bufferTxtStateObj, 0, bufferTxtStateObj.Length);
                        stateObj.Buffer = bufferTxtStateObj;
                    }
                    Logger.debug("set buffer size =>" + buffer.Length);

                    //
                    if (!IsSocketReadyToReceive(stateObj))
                    {
                        stateObj.SocMessage = "소켓수신상태 Disconnected or Error.";
                        Logger.info(stateObj);
                        return;
                    }

                    int receivingByteInfo = 0;

                    while (true)//건별 메시지 수신
                    {
                        stateObj.Status = SocHandlerStatus.RECEIVING;
                        if (stateObj.FtpStatus != FTPStatus.RECEIVE_STREAM)//텍스트
                        {
                            stateObj.SocMessage = "메시지 수신대기";
                            Logger.debug(stateObj);
                            OnSocStatusChangedOnDebug(new SocStatusEventArgs(stateObj));
                        }
                        recv = clientSoc.Receive(buffer);

                        if (recv == 0)                   //수신데이터 없음
                        {
                            if (connectionCheckCnt > 10) //10회반복 데이터없으면 에러처리
                            {
                                stateObj.Data = string.Format(MsgDef.MSG_TEXT_FMT, MsgDef.MSG_TEXT, "TEST");
                                if (SendMsg(stateObj) == SocCode.SOC_ERR_CODE)
                                {
                                    stateObj.SocMessage = "소켓수신상태 Disconnected or Error.";
                                    Logger.info(stateObj);
                                    return;
                                }
                            }
                            connectionCheckCnt++;
                        }

                        if (stateObj.FtpStatus != FTPStatus.RECEIVE_STREAM)//텍스트
                        {
                            //텍스트는 메시지가 잘려서 넘어오는 경우보다
                            //여러건이 연결해서 한꺼번에 오는 경우가 있어 이를 감안함.
                            int msgBufSize = 0;
                            while (buffer.Length > 0)
                            {
                                //잘라서 처리
                                string resultMsg = SocUtils.GetMsgByPrefixLengthInfo(ref buffer, recv, ref msgBufSize);
                                if (resultMsg == null)
                                {
                                    break;
                                }

                                stateObj.Data       = resultMsg;
                                stateObj.BufferSize = msgBufSize;
                                stateObj.SocMessage = string.Format("일반메시지수신 Msg[{0}] Size[{0}]", stateObj.Data, stateObj.BufferSize);
                                Logger.debug(stateObj);
                                OnSocStatusChangedOnDebug(new SocStatusEventArgs(stateObj));
                                this.ProcessMsg(stateObj);
                            }
                        }
                        else
                        {
                            //FTP는 한 블록을 보낼때마다, 우선 블록사이즈정보를 보내고 실제바이트를 전송한다.
                            if (receivingByteInfo == 0)
                            {
                                receivingByteInfo = SocUtils.ConvertByteArrayToFileSize(buffer);
                                if (receivingByteInfo != 0)//블록사이즈정보있는 헤더
                                {
                                    recv = recv - SocConst.PREFIX_BYTE_INFO_LENGTH;
                                    //Logger.debug(string.Format("BlockCopy 헤더 receivingByteInfo[{0}]stateObj.BufferSize[{1}]recv[{2}]", receivingByteInfo, stateObj.BufferSize, recv));
                                    Buffer.BlockCopy(buffer, SocConst.PREFIX_BYTE_INFO_LENGTH, stateObj.Buffer, stateObj.BufferSize, recv);
                                }
                                else //중간부분
                                {    // error or abnormal stop , cancel
                                    //Logger.debug(string.Format("BlockCopy 헤더없는블록 receivingByteInfo[{0}]stateObj.BufferSize[{1}]recv[{2}]", receivingByteInfo, stateObj.BufferSize, recv));
                                    Buffer.BlockCopy(buffer, 0, stateObj.Buffer, stateObj.BufferSize, recv);
                                    stateObj.Data += Encoding.UTF8.GetString(buffer, 0, recv);
                                }
                                stateObj.SocMessage = string.Format("파일수신바이트[{0}].", recv);
                                //Logger.debug(string.Format("receivingByteInfo==0: receivingByteInfo[{0}]recv[{1}]", receivingByteInfo, recv));
                            }
                            else
                            {
                                //Logger.debug(string.Format("BlockCopy 중간부분 receivingByteInfo[{0}]stateObj.BufferSize[{1}]recv[{2}]", receivingByteInfo, stateObj.BufferSize, recv));
                                Buffer.BlockCopy(buffer, 0, stateObj.Buffer, stateObj.BufferSize, recv);
                                stateObj.SocMessage = string.Format("파일수신바이트[{0}].", recv);
                            }
                            stateObj.BufferSize += recv;
                            //Logger.debug(string.Format("stateObj.BufferSize += recv: stateObj.BufferSize[{0}]recv[{1}]", stateObj.BufferSize, recv));
                            //Logger.debug(stateObj.SocMessage);
                            //OnSocStatusChanged(new SocStatusEventArgs(stateObj));
                        }

                        if ((receivingByteInfo == 0 /*&& clientSoc.Available == 0*/) || //텍스트이거나,
                            (receivingByteInfo > 0 && receivingByteInfo == stateObj.BufferSize))    //바이너리인데 buffer리딩이 완료된 경우
                        {
                            break;
                        }
                    }//while (true)//건별 메시지 수신

                    if (receivingByteInfo > 0 && receivingByteInfo == stateObj.BufferSize) //바이너리인데 buffer리딩이 완료된 경우
                    {
                        stateObj.SocMessage = string.Format("메시지수신 완료바이트Size[{0}]", stateObj.BufferSize);
                        Logger.debug(stateObj);
                        OnSocStatusChangedOnDebug(new SocStatusEventArgs(stateObj));
                        this.ProcessMsg(stateObj);
                        //리셋
                        receivingByteInfo   = 0;
                        stateObj.BufferSize = 0;
                    }
                } //while (true)
            } catch (WeDoFTPCancelException wde) {
                CloseClient(clientSoc);
                StopListening();
                setErrorMessage(wde, stateObj);
            }
            catch (Exception e)
            {
                CloseClient(clientSoc);
                setErrorMessage(e, "수신에러:" + e.ToString());
            }
        }
Ejemplo n.º 9
0
        public override void ProcessMsg(StateObject socObj)
        {
            base.ProcessMsg(socObj);
            StateObject stateObj = (StateObject)socObj;

            switch (stateObj.FtpStatus)
            {
            case FTPStatus.NONE:
                #region FTPStatus.NONE
            {
                //파일수신정보
                if (stateObj.Cmd == MsgDef.MSG_SEND_FILE)
                {
                    string[] list = stateObj.Data.Split(SocConst.TOKEN);

                    stateObj.FileName = list[1];
                    stateObj.FileSize = Convert.ToInt64(list[2]);
                    //중복방지 파일명
                    stateObj.FullFileName = SocUtils.GetValidFileName(this.savePath, stateObj.FileName, 0);
                    stateObj.TempFileName = stateObj.FullFileName + SocConst.TEMP_FILE_SUFFIX;

                    //수신대기상태
                    stateObj.Data = MsgDef.MSG_ACK;

                    //파일수신상태로 변경
                    stateObj.Status     = SocHandlerStatus.RECEIVING;
                    stateObj.FtpStatus  = FTPStatus.RECEIVE_STREAM;
                    stateObj.SocMessage = string.Format("파일수신정보[{0}/{1}]==>[{2}]/FTPStatus.RECEIVE_STREAM",
                                                        stateObj.FileName, stateObj.FileSize, stateObj.FullFileName);

                    Logger.info(stateObj);
                    OnSocStatusChangedOnInfo(new SocStatusEventArgs(stateObj));

                    File.Delete(stateObj.TempFileName);
                    FileStream fs = File.Open(stateObj.TempFileName, FileMode.Create, FileAccess.Write);
                    fs.Close();

                    //수신대기 알림
                    if (SendMsg(stateObj) == SocCode.SOC_ERR_CODE)
                    {
                        closeOnError(stateObj, string.Format("파일수신 대기메시지 전송에러:FTPStatus.NONE/Msg[{0}]", stateObj.Data));
                    }
                }
                else if (stateObj.Cmd == MsgDef.MSG_KEY_INFO)
                {           //클라이언트 key ( senderid_filename_filesize_receiverid )
                    string[] msgToken = stateObj.Data.Split('|');
                    string   userKey  = msgToken[1];
                    lock (mClientTableLock)
                    {
                        stateObj.Key           = userKey;
                        mClientKeyMap[userKey] = stateObj.Soc.RemoteEndPoint.ToString();
                    }
                    if (SendMsg(stateObj) == SocCode.SOC_ERR_CODE)
                    {
                        stateObj.MsgStatus = MSGStatus.ERROR;
                        throw new Exception(string.Format("FTP메시지 전송에러:MSG_TEXT/Msg[{0}]", stateObj.Data));
                    }
                }
                else
                {
                    closeOnError(stateObj, string.Format("Unknown Msg[{0}]:FTPStatus.NONE", stateObj.Data));
                }
            }
            break;

                #endregion
                #region FTPStatus.RECEIVE_STREAM
            //파일 수신
            case FTPStatus.RECEIVE_STREAM:
            {
                //파일 전송 취소인경우
                if (stateObj.Cmd == MsgDef.MSG_CANCEL)
                {
                    //수신종료
                    stateObj.Data = MsgDef.MSG_BYE;
                    if (SendMsg(stateObj) == SocCode.SOC_ERR_CODE)
                    {
                        closeOnError(stateObj, string.Format("파일수신종료메시지 전송에러:FTPStatus.RECEIVE_STREAM/Msg[{0}]", stateObj.Data));
                    }

                    //종료로 상태변경
                    stateObj.FtpStatus  = FTPStatus.SENT_DONE;
                    stateObj.Status     = SocHandlerStatus.FTP_CANCELED;
                    stateObj.SocMessage = string.Format("파일수신종료/Msg[{0}]", MsgDef.MSG_BYE);
                    Logger.info(stateObj);
                    OnSocStatusChangedOnInfo(new SocStatusEventArgs(stateObj));
                    closeFTPConnection(stateObj);
                    break;
                }
                //수신파일스트림 Write
                FileStream fs = File.Open(stateObj.TempFileName, FileMode.Append, FileAccess.Write);
                fs.Write(stateObj.Buffer, 0, stateObj.BufferSize);
                fs.Close();
                stateObj.FileSizeDone += stateObj.BufferSize;

                stateObj.SocMessage = string.Format("수신중인 바이트:rcvSize[{0}]/fileSize[{1}]", stateObj.FileSizeDone, stateObj.FileSize);
                Logger.debug(stateObj);
                //수신완료
                if (stateObj.FileSizeDone >= stateObj.FileSize)
                {
                    File.Move(stateObj.TempFileName, stateObj.FullFileName);
                    stateObj.SocMessage = string.Format("수신완료한 바이트 rcvSize[{0}]/fileSize[{1}]", stateObj.FileSizeDone, stateObj.FileSize);
                    stateObj.FtpStatus  = FTPStatus.SENT_DONE;
                }

                stateObj.Data = string.Format(MsgDef.MSG_RCVCHECK_FMT, MsgDef.MSG_RCVCHECK, stateObj.BufferSize);
                OnSocStatusChangedOnInfo(new SocStatusEventArgs(stateObj));

                stateObj.SocMessage = string.Format("수신바이트 확인전송:Msg[{0}]", stateObj.Data);
                Logger.debug(stateObj);

                if (SendMsg(stateObj) == SocCode.SOC_ERR_CODE)
                {
                    closeOnError(stateObj, string.Format("수신바이트 확인전송에러:FTPStatus.RECEIVE_STREAM/Msg[{0}]", stateObj.Data));
                }
            }
            break;

                #endregion
                #region FTPStatus.RECEIVE_CANCELED
            //수신취소
            case FTPStatus.RECEIVE_CANCELED:
            {
                //취소전송
                stateObj.Data = MsgDef.MSG_CANCEL;
                if (SendMsg(stateObj) == SocCode.SOC_ERR_CODE)
                {
                    closeOnError(stateObj, string.Format("파일수신취소메시지 전송에러:FTPStatus.RECEIVE_CANCELED/Msg[{0}]", stateObj.Data));
                }

                //완료로 상태변경
                stateObj.FtpStatus  = FTPStatus.SENT_DONE;
                stateObj.Status     = SocHandlerStatus.FTP_SERVER_CANCELED;
                stateObj.SocMessage = string.Format("파일수신취소/Msg[{0}]", stateObj.Data);
                Logger.info(stateObj);
                OnSocStatusChangedOnInfo(new SocStatusEventArgs(stateObj));
            }
            break;

                #endregion
                #region FTPStatus.SENT_DONE
            //수신완료
            case FTPStatus.SENT_DONE:
                if (stateObj.Cmd == MsgDef.MSG_COMPLETE)
                {
                    //수신종료
                    stateObj.Data = MsgDef.MSG_BYE;

                    if (SendMsg(stateObj) == SocCode.SOC_ERR_CODE)
                    {
                        closeOnError(stateObj, string.Format("파일수신종료메시지 전송에러:FTPStatus.SENT_DONE/Msg[{0}]", stateObj.Data));
                    }

                    stateObj.Status     = SocHandlerStatus.FTP_END;
                    stateObj.SocMessage = string.Format("파일수신종료:{0}", MsgDef.MSG_BYE);
                    Logger.info(stateObj);
                    OnSocStatusChangedOnInfo(new SocStatusEventArgs(stateObj));
                    closeFTPConnection(stateObj);
                }
                else
                {
                    closeOnError(stateObj, string.Format("Unknown Msg[{0}]:FTPStatus.SENT_DONE", stateObj.Data));
                }
                break;
                #endregion
            }
            stateObj.SocMessage = string.Format("Ftp ProcessMsg End");
            if (stateObj.AbortFTP)
            {
                stateObj.FtpStatus = FTPStatus.RECEIVE_CANCELED;
                stateObj.AbortFTP  = false;
            }
            Logger.debug(stateObj);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// TcpClient인 경우 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void ProcessOnMessageReceived(object sender, SocStatusEventArgs e)
        {
            //OnMessageReceived(e);
            switch (e.Status.Cmd)
            {
            case MsgDef.MSG_TEXT:
            {
                OnTCPMsgReceived(e);
                break;
            }

            case MsgDef.MSG_BYE:
                //처리없음
                break;

            case MsgDef.MSG_FTP_INFO_TO_RCV:
                //받는쪽. 파일전송의사가 전달됨
                //1. 서버로 재전송
            {
                //string msg = e.Status.Data.Substring(MsgDef.MSG_TEXT.Length+1); //"MSG|..."
                //this.Send(e.Status.Data);
                //2. 하위단에서 이벤트처리토록 둠.
                OnManagerStatusChanged(string.Format("2단계 서버 =>전송자 파일전송공지[{0}]", e.Status.Data));
                string[]  msgToken = e.Status.Data.Split(SocConst.TOKEN);
                string    senderId = msgToken[1];
                string    fileName = msgToken[2];
                long      fileSize = Convert.ToInt64(msgToken[3]);
                string    mapKey   = SocUtils.GenerateFTPClientKey(mKey, fileName, fileSize, senderId);
                FTPRcvObj rcvObj   = new FTPRcvObj((IPEndPoint)e.Status.Soc.RemoteEndPoint, mapKey, fileName, fileSize, senderId);
                OnFTPSendingNotified(new SocFTPInfoEventArgs <FTPRcvObj>(rcvObj));
                break;
            }

            case MsgDef.MSG_FTP_READY_TO_SND:    //header|(senderid|ip)|filename|filesize|(receiverId|ip or m) 'm'은 서버
            {
                //수신준비된것이 확인됨.==> FTP기동
                //필요한 인자: 파일정보, 수신자정보
                OnManagerStatusChanged(string.Format("4단계 서버=>전송자 파일수신준비완료[{0}]", e.Status.Data));
                string[]   msgToken     = e.Status.Data.Split(SocConst.TOKEN);
                string     fileName     = msgToken[2];
                long       fileSize     = Convert.ToInt64(msgToken[3]);
                string     receiverId   = msgToken[4];
                string     mapKey       = SocUtils.GenerateFTPClientKey(mKey, fileName, fileSize, receiverId);
                FTPSendObj sendObj      = mFileInfoMap[mapKey];
                string     fullFileName = sendObj.FileName;

                if (mFileInfoMap.ContainsKey(mapKey))
                {
                    mFileInfoMap.Remove(mapKey);
                }
                StartFTP(sendObj.RemoteEndPoint, receiverId, fullFileName, fileSize);
                Thread thServer = new Thread(new ParameterizedThreadStart(SendFile));
                thServer.Start((object)mapKey);

                OnFTPSendingAccepted(new SocFTPInfoEventArgs <FTPSendObj>(sendObj));
                break;
            }

            case MsgDef.MSG_FTP_REJECT_TO_SND:    //header|(senderid|ip)|filename|filesize|(receiverId|ip or m) 'm'은 서버
            {
                //파일전송의사가 전달됨
                //처리없음
                OnManagerStatusChanged(string.Format("4단계 서버=>전송자 파일수신준비거부[{0}]", e.Status.Data));
                string[]   msgToken   = e.Status.Data.Split(SocConst.TOKEN);
                string     fileName   = msgToken[2];
                long       fileSize   = Convert.ToInt64(msgToken[3]);
                string     receiverId = msgToken[4];
                string     mapKey     = SocUtils.GenerateFTPClientKey(mKey, fileName, fileSize, receiverId);
                FTPSendObj sendObj    = mFileInfoMap[mapKey];
                OnFTPSendingRejected(new SocFTPInfoEventArgs <FTPSendObj>(sendObj));
                break;
            }

            default:
                break;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// FTP전송 통지에 대해 거부
        /// </summary>
        /// <param name="remoteIE"></param>
        /// <param name="receiverId"></param>
        /// <param name="fileName"></param>
        /// <param name="fileSize"></param>
        /// <returns></returns>
        public bool NotifyFTPReject(IPEndPoint remoteIE, string senderId, string fileName, long fileSize)
        {
            string msgRequest = String.Format(MsgDef.FMT_FTP_REJECT_TO_SVR, MsgDef.MSG_FTP_REJECT_TO_SVR, senderId, SocUtils.GetFileName(fileName), fileSize, this.mKey);

            Logger.info(string.Format("3단계 수신자=>서버 파일수신준비거부 NotifyFTPReject[{0}]", msgRequest));
            return(_NotifyFTPMsg(msgRequest, remoteIE, senderId, fileName, fileSize, this.mKey));
        }
Ejemplo n.º 12
0
        /**
         * 1. (A->B) 서버에 파일전송 알림
         *    FTP_INFO_TO_SVR 전송자-파일-수신자
         *    action: B->C로 전달
         * 2. (B->C) 파일정보 알려줌
         *    FTP_INFO_TO_RCV 전송자-파일-수신자
         *    action: C->B로 리턴. 추가조치없음
         * ----->FTP 리스너 기동
         * 3.(C->B) 수신준비대기/거부 통지
         *    FTP_READY_TO_SVR/FTP_REJECT_TO_SVR 전송자-파일-수신자
         *    action: A로 릴레이
         * 4. (B->A) 수신준비대기/거부 통지
         *   FTP_READY_TO_SND/FTP_REJECT_TO_SND 전송자-파일-수신자
         *   action: 파일전송소켓 접속
         * ----->FTP접속--------------------------------------
         * 파일전송 알림 1번작업
         * 1. Cli A Send File Noti , Wait for Ack
         * 2. Svr B Run FTPListener
         * 3. Svr B Send Info | Nack
         * 6. Cli A Run FTPClient
         * 7. Cli A Done
         * 8. Cli A BYE
         */
        public bool NotifyFTPStart(IPEndPoint remoteIE, string receiverId, string fileName, long fileSize)
        {
            string msgRequest = String.Format(MsgDef.FMT_FTP_INFO_TO_SVR, MsgDef.MSG_FTP_INFO_TO_SVR, this.mKey, SocUtils.GetFileName(fileName), fileSize, receiverId);

            Logger.info(string.Format("1단계 전송자=>서버 파일전송공지 NotifyFTPStart[{0}]", msgRequest));
            return(_NotifyFTPMsg(msgRequest, remoteIE, this.mKey, fileName, fileSize, receiverId));
        }
Ejemplo n.º 13
0
        //파일전송
        public bool InternalSendFile()
        {
            bool result = true;

            //using(Stream source = File.OpenRead(mFilePath+"\\"+mFileName)) {
            using (mFs = new FileStream(mFullPath, FileMode.Open, FileAccess.Read))
            {
                try
                {
                    Array.Clear(bufferBin, 0, bufferBin.Length);
                    byte[] buffer = bufferBin;
                    byte[] bPrefix;
                    int    bytesRead;
                    long   curRead = 0;
                    mSocClient.SetBinary();
                    while ((bytesRead = mFs.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        //취소시 취소처리
                        if (IsCanceled)
                        {
                            result = _InternalCancelSending();
                            break;
                        }
                        //전송할 byte정보
                        bPrefix             = SocUtils.ConvertFileSizeToByteArray(bytesRead);
                        curRead            += bytesRead;
                        stateObj.SocMessage = string.Format("전송바이트Size[{0}]/[{1}]", curRead, stateObj.FileSize);
                        Logger.info(stateObj);
                        //전송할 byte정보 전송
                        int bytePrefixSize = mSocClient.Send(bPrefix, bPrefix.Length);
                        //전송할 스트림 전송
                        int byteSize = mSocClient.Send(buffer, bytesRead);
                        if (bytePrefixSize != bPrefix.Length || byteSize != bytesRead)
                        {
                            _internalHandleOnError(string.Format("전송 Error : 확인Size[{0}]/전송Size[{1}] file[{0}]", bytesRead, byteSize, mFullPath));
                            result = false;
                            break;
                        }
                        stateObj.BufferSize   = bytesRead;
                        stateObj.FileSizeDone = curRead;
                        stateObj.Status       = SocHandlerStatus.FTP_SENDING;
                        OnSocStatusChangedOnInfo(new SocStatusEventArgs(stateObj));

                        //수신정보 확인
                        string line = mSocClient.ReadLine();
                        if (line == MsgDef.MSG_CANCEL)
                        {
                            result = _InternalCancelByServer();
                            break;
                        }
                        else if (line == string.Format(MsgDef.MSG_RCVCHECK_FMT, MsgDef.MSG_RCVCHECK, bytesRead))
                        {
                            continue;
                        }
                        else
                        {
                            _internalHandleOnError(string.Format("수신 SizeCheck Error Msg[{0}]/실제전송byte수[{1}]", line, bytesRead));
                            result = false;
                            break;
                        }
                    }
                }
                finally
                {
                    if (mFs != null)
                    {
                        mFs.Close();
                    }
                    mSocClient.SetText();
                }
            }
            return(result);
        }