/****************************** * 说明:下载Scoket通讯 * 创建人:龚宇超 * 创建日期:2018-01-23 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using Lskj.SocketService; namespace Lskj.SocketClient { public class ClientDownLoadSocket : ClientBaseSocket { public ClientDownLoadSocket() : base() { _protocolFlag = ProtocolFlag.Download; } public bool DoDownLoad(string dirName, string fileName, ref long fileSize) { bool bConnect = ReConnectAndLogin(); //检测连接是否还在,如果断开则重连并登录 if (!bConnect) return bConnect; try { _outgoingDataAssembler.Clear(); _outgoingDataAssembler.AddRequest(); _outgoingDataAssembler.AddCommand(ProtocolKey.Download); _outgoingDataAssembler.AddValue(ProtocolKey.DirName, dirName); _outgoingDataAssembler.AddValue(ProtocolKey.FileName, fileName); 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; } } } }