/// <summary>
 /// 发送文件初始化;发送文件前先发一个小包让对方进行确认
 /// </summary>
 /// <param name="date">数据</param>
 /// <param name="textCode">什么文件</param>
 /// <param name="state">StateBase</param>
 /// <returns>加密之后的包头</returns>
 internal static byte[] SendHeadEncryption(byte[] date, byte textCode, StateBase state)
 {
     state.SendFile           = new FileBase(date);
     state.SendFile.FileLabel = RandomPublic.RandomNumber(14562);
     byte[] headDate = new byte[11];
     headDate[0] = PasswordCode._bigDateCode; headDate[1] = PasswordCode._fileHeadCode; headDate[2] = textCode;
     ByteToDate.IntToByte(state.SendFile.FileLabel, 3, headDate);
     ByteToDate.IntToByte(date.Length, 7, headDate);
     return(headDate);
 }
示例#2
0
 /// <summary>
 /// 一个普通的对数据主体部分进行加密;
 /// </summary>
 /// <param name="date">要加密的数据</param>
 /// <param name="textCode"></param>
 /// <param name="state">StateBase</param>
 /// <returns>加密之后的数据</returns>
 private static byte[] encryptionTemporary(byte[] date, byte textCode, StateBase state)
 {
     if (date.Length > state.BufferSize - 20)
     {
         return(EncryptionDecryptSeparateDate.SendHeadEncryption(date, textCode, state)); //超出通过文件系统发送
     }
     state.SendDateLabel = RandomPublic.RandomNumber(16787);                              //给发送的数据进行编号
     byte[] dateOverall = ByteToDate.OffsetEncryption(date, state.SendDateLabel, 2);
     dateOverall[0] = PasswordCode._commonCode; dateOverall[1] = textCode;
     return(dateOverall);
 }
示例#3
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="fileLable">文件标签</param>
        /// <param name="fileName">文件地址</param>
        /// <param name="stateOne">StateBase</param>
        /// <returns>形成之后的数据</returns>
        internal byte[] Send(ref int fileLable, string fileName, StateBase stateOne)
        {
            int        fileLenth = 0;
            FileStream fs;

            try
            {
                fs        = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                fileLenth = (int)fs.Length;
            }
            catch (Exception Ex) { throw new Exception(Ex.Message); }
            fileLable = RandomPublic.RandomNumber(16787);

            FileState fileState = new FileState(fileLable, fileLenth, fileName, fs);

            fileState.StateOne = stateOne;
            FS.Add(fileState);
            byte[] haveByte = EncryptionDecryptFile.FileHeadEncryption(fileState);
            return(haveByte);
        }
示例#4
0
 /// <summary> 启动客户端基础的一个线程 </summary>
 private void start()
 {
     //  如果是重连的延迟10秒
     if (reconnectOn)
     {
         Thread.Sleep(9000 + RandomPublic.RandomTime(1000));
     }
     try
     {
         Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.SendTimeout = 1000;
         socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
         socket.BeginConnect(IpEndPoint, new AsyncCallback(AcceptCallback), socket);
         loginTimeout(socket);//超时判断方法
     }
     catch (Exception Ex)
     {
         loginFailure(Ex.Message);//登录失败触发
     }
 }