ab56a9bcf7
SVN-Revision: r240
294 lines
8.4 KiB
C#
294 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Lskj.SocketService
|
|
{
|
|
public class ProtocolConst
|
|
{
|
|
/// <summary>
|
|
/// 解析命令初始缓存大小
|
|
/// </summary>
|
|
public static int InitBufferSize = 1024 * 4;
|
|
/// <summary>
|
|
/// IOCP接收数据缓存大小,设置过小会造成事件响应增多,设置过大会造成内存占用偏多
|
|
/// </summary>
|
|
public static int ReceiveBufferSize = 1024 * 4;
|
|
/// <summary>
|
|
/// Socket超时设置为60秒
|
|
/// </summary>
|
|
public static int SocketTimeOutMS = 60 * 1000;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 协议标记
|
|
/// </summary>
|
|
public enum ProtocolFlag
|
|
{
|
|
/// <summary>
|
|
/// 默认协议
|
|
/// </summary>
|
|
None = 0,
|
|
/// <summary>
|
|
/// SQL查询协议
|
|
/// </summary>
|
|
SQL = 1,
|
|
/// <summary>
|
|
/// 上传协议
|
|
/// </summary>
|
|
Upload = 2,
|
|
/// <summary>
|
|
/// 下载协议
|
|
/// </summary>
|
|
Download = 3,
|
|
/// <summary>
|
|
/// 远程文件流协议
|
|
/// </summary>
|
|
RemoteStream = 4,
|
|
/// <summary>
|
|
/// 吞吐量测试协议
|
|
/// </summary>
|
|
Throughput = 5,
|
|
Control = 8,
|
|
LogOutput = 9,
|
|
}
|
|
|
|
public class ProtocolKey
|
|
{
|
|
public static string Request = "Request";
|
|
public static string Response = "Response";
|
|
public static string LeftBrackets = "[";
|
|
public static string RightBrackets = "]";
|
|
public static string ReturnWrap = "\r\n";
|
|
public static string EqualSign = "=";
|
|
public static string Command = "Command";
|
|
public static string Code = "Code";
|
|
public static string Message = "Message";
|
|
public static string UserName = "UserName";
|
|
public static string Password = "Password";
|
|
public static string FileName = "FileName";
|
|
public static string Item = "Item";
|
|
public static string ParentDir = "ParentDir";
|
|
public static string DirName = "DirName";
|
|
public static char TextSeperator = (char)1;
|
|
public static string FileSize = "FileSize";
|
|
public static string PacketSize = "PacketSize";
|
|
|
|
public static string FileExists = "FileExists";
|
|
public static string OpenFile = "OpenFile";
|
|
public static string SetSize = "SetSize";
|
|
public static string GetSize = "GetSize";
|
|
public static string SetPosition = "SetPosition";
|
|
public static string GetPosition = "GetPosition";
|
|
public static string Read = "Read";
|
|
public static string Write = "Write";
|
|
public static string Seek = "Seek";
|
|
public static string CloseFile = "CloseFile";
|
|
public static string Mode = "Mode";
|
|
public static string Size = "Size";
|
|
public static string Position = "Position";
|
|
public static string Count = "Count";
|
|
public static string Offset = "Offset";
|
|
public static string SeekOrigin = "SeekOrigin";
|
|
public static string Login = "Login";
|
|
public static string Active = "Active";
|
|
public static string GetClients = "GetClients";
|
|
public static string Dir = "Dir";
|
|
public static string CreateDir = "CreateDir";
|
|
public static string DeleteDir = "DeleteDir";
|
|
public static string FileList = "FileList";
|
|
public static string DeleteFile = "DeleteFile";
|
|
public static string Upload = "Upload";
|
|
public static string Data = "Data";
|
|
public static string Eof = "Eof";
|
|
public static string Download = "Download";
|
|
public static string SendFile = "SendFile";
|
|
public static string CyclePacket = "CyclePacket";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 协议代码
|
|
/// </summary>
|
|
public class ProtocolCode
|
|
{
|
|
/// <summary>
|
|
/// 成功代码
|
|
/// </summary>
|
|
public static int Success = 0x00000000;
|
|
/// <summary>
|
|
/// 无效命令代码
|
|
/// </summary>
|
|
public static int NotExistCommand = Success + 0x01;
|
|
/// <summary>
|
|
/// 错误包代码
|
|
/// </summary>
|
|
public static int PacketLengthError = Success + 0x02;
|
|
/// <summary>
|
|
/// 格式包错误代码
|
|
/// </summary>
|
|
public static int PacketFormatError = Success + 0x03;
|
|
/// <summary>
|
|
/// 未知错误代码
|
|
/// </summary>
|
|
public static int UnknowError = Success + 0x04;
|
|
public static int CommandNoCompleted = Success + 0x05;
|
|
/// <summary>
|
|
/// 参数错误代码
|
|
/// </summary>
|
|
public static int ParameterError = Success + 0x06;
|
|
/// <summary>
|
|
/// 用户密码错误代码
|
|
/// </summary>
|
|
public static int UserOrPasswordError = Success + 0x07;
|
|
/// <summary>
|
|
/// 未登录错误代码
|
|
/// </summary>
|
|
public static int UserHasLogined = Success + 0x08;
|
|
/// <summary>
|
|
/// 文件不存在代码
|
|
/// </summary>
|
|
public static int FileNotExist = Success + 0x09;
|
|
/// <summary>
|
|
/// 无法打开文件错误代码
|
|
/// </summary>
|
|
public static int NotOpenFile = Success + 0x0A;
|
|
/// <summary>
|
|
/// 文件被使用错误代码
|
|
/// </summary>
|
|
public static int FileIsInUse = Success + 0x0B;
|
|
/// <summary>
|
|
/// 目录不存在代码
|
|
/// </summary>
|
|
public static int DirNotExist = 0x02000001;
|
|
/// <summary>
|
|
/// 创建目录错误代码
|
|
/// </summary>
|
|
public static int CreateDirError = 0x02000002;
|
|
/// <summary>
|
|
/// 删除目录错误代码
|
|
/// </summary>
|
|
public static int DeleteDirError = 0x02000003;
|
|
/// <summary>
|
|
/// 删除文件错误代码
|
|
/// </summary>
|
|
public static int DeleteFileFailed = 0x02000007;
|
|
/// <summary>
|
|
/// 文件大小错误代码
|
|
/// </summary>
|
|
public static int FileSizeError = 0x02000008;
|
|
|
|
/// <summary>
|
|
/// <para>说明:获取错误代码</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-24 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="errorCode">The error code.</param>
|
|
/// <returns>System.String.</returns>
|
|
public static string GetErrorCodeString(int errorCode)
|
|
{
|
|
string errorString = null;
|
|
if (errorCode == NotExistCommand)
|
|
errorString = "Not Exist Command";
|
|
return errorString;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自定义命令
|
|
/// </summary>
|
|
public enum RemoteStreamSocketCommand
|
|
{
|
|
None = 0,
|
|
FileExists = 1,
|
|
OpenFile = 2,
|
|
SetSize = 3,
|
|
GetSize = 4,
|
|
SetPosition = 5,
|
|
GetPosition = 6,
|
|
Read = 7,
|
|
Write = 8,
|
|
Seek = 9,
|
|
CloseFile = 10,
|
|
}
|
|
|
|
/// <summary>
|
|
/// 远程传输支持协议命令
|
|
/// </summary>
|
|
public enum RemoteStreamMode
|
|
{
|
|
Read = 0,
|
|
ReadWrite = 1,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Control 传输支持协议命令
|
|
/// </summary>
|
|
public enum ControlSocketCommand
|
|
{
|
|
None = 0,
|
|
Login = 1,
|
|
Active = 2,
|
|
GetClients = 3,
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传支持协议命令
|
|
/// </summary>
|
|
public enum UploadSocketCommand
|
|
{
|
|
None = 0,
|
|
Login = 1,
|
|
Active = 2,
|
|
Dir = 3,
|
|
CreateDir = 4,
|
|
DeleteDir = 5,
|
|
FileList = 6,
|
|
DeleteFile = 7,
|
|
Upload = 8,
|
|
Data = 9,
|
|
Eof = 10,
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下载支持协议命令
|
|
/// </summary>
|
|
public enum DownloadSocketCommand
|
|
{
|
|
None = 0,
|
|
Login = 1,
|
|
Active = 2,
|
|
Dir = 3,
|
|
FileList = 4,
|
|
Download = 5,
|
|
}
|
|
|
|
/// <summary>
|
|
/// SQL支持协议命令
|
|
/// </summary>
|
|
public enum SQLSocketCommand
|
|
{
|
|
None = 0,
|
|
Login = 1,
|
|
Active = 2,
|
|
SQLOpen = 3,
|
|
SQLExec = 4,
|
|
BeginTrans = 5,
|
|
CommitTrans = 6,
|
|
RollbackTrans = 7,
|
|
}
|
|
|
|
/// <summary>
|
|
/// 吞吐量支持协议
|
|
/// </summary>
|
|
public enum ThroughputSocketCommand
|
|
{
|
|
None = 0,
|
|
CyclePacket = 1,
|
|
}
|
|
}
|