/****************************** * 说明:上传Socket通讯 * 创建人:龚宇超 * 创建日期:2018-01-23 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Lskj.SocketService; namespace Lskj.SocketClient { /// /// 上传Socket通讯协议 /// class ClientUploadSocket : ClientBaseSocket { public ClientUploadSocket() : base() { _protocolFlag = ProtocolFlag.Upload; } /// /// 说明:上传 /// 创建人:龚宇超 /// 创建日期:2018-01-24 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 目录 /// 文件 /// 文件大小 /// true if XXXX, false otherwise. public bool DoUpload(string dirName, string fileName, ref long fileSize) { bool bConnect = ReConnectAndLogin(); //检测连接是否还在,如果断开则重连并登录 if (!bConnect) return bConnect; try { _outgoingDataAssembler.Clear(); _outgoingDataAssembler.AddRequest(); _outgoingDataAssembler.AddCommand(ProtocolKey.Upload); _outgoingDataAssembler.AddValue(ProtocolKey.DirName, dirName); _outgoingDataAssembler.AddValue(ProtocolKey.FileName, fileName); _outgoingDataAssembler.AddValue(ProtocolKey.FileSize, fileSize); SendCommand(); bool bSuccess = RecvCommand(); if (bSuccess) { bSuccess = CheckErrorCode(); if (bSuccess) { bSuccess = _incomingDataParser.GetValue(ProtocolKey.FileSize, ref fileSize); } return bSuccess; } else return false; } catch (Exception E) { //记录日志 _errorString = E.Message; return false; } } public bool DoData(byte[] buffer, int offset, int count) { try { _outgoingDataAssembler.Clear(); _outgoingDataAssembler.AddRequest(); _outgoingDataAssembler.AddCommand(ProtocolKey.Data); SendCommand(buffer, offset, count); return true; } catch (Exception E) { //记录日志 _errorString = E.Message; return false; } } public bool DoEof(Int64 fileSize) { try { _outgoingDataAssembler.Clear(); _outgoingDataAssembler.AddRequest(); _outgoingDataAssembler.AddCommand(ProtocolKey.Eof); SendCommand(); bool bSuccess = RecvCommand(); if (bSuccess) return CheckErrorCode(); else return false; } catch (Exception E) { //记录日志 _errorString = E.Message; return false; } } } }