本文整理汇总了C#中ZyGames.Framework.RPC.IO.MessageHead类的典型用法代码示例。如果您正苦于以下问题:C# MessageHead类的具体用法?C# MessageHead怎么用?C# MessageHead使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageHead类属于ZyGames.Framework.RPC.IO命名空间,在下文中一共展示了MessageHead类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecodePacket
protected override bool DecodePacket(MessageStructure reader, MessageHead head)
{
responsePack = ProtoBufUtils.Deserialize<Response1010Pack>(netReader.Buffer);
string responseDataInfo = "";
responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Request1010Pack>(req) + "\n";
responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<Response1010Pack>(responsePack) + "\n";
DecodePacketInfo = responseDataInfo;
int childStepId = getChild(1010);
System.Console.WriteLine("childStepID:" + childStepId);
if (childStepId > 0)
{
System.Collections.Generic.Dictionary<string, string> dic = new System.Collections.Generic.Dictionary<string, string>();
/*
req.UserID = GetParamsData("UserID", req.UserID);
req.identify = GetParamsData("identify", req.identify);
req.version = GetParamsData("version", req.version);
req.the3rdUserID = GetParamsData("the3rdUserID", req.the3rdUserID);
req.happyPoint = GetParamsData("happyPoint", req.happyPoint);
req.Rate = GetParamsData("Rate", req.Rate);
req.index = GetParamsData("index", req.index);
req.strThe3rdUserID = GetParamsData("strThe3rdUserID", req.strThe3rdUserID);
req.typeUser = GetParamsData("typeUser", req.typeUser);
*/
dic.Add("UserID", req.UserID.ToString());
dic.Add("index", responsePack.index.ToString());
dic.Add("the3rdUserID", req.the3rdUserID.ToString());
dic.Add("strThe3rdUserID", req.strThe3rdUserID);
SetChildStep(childStepId.ToString(), _setting,dic);
}
return true;
}
示例2: ResponseError
public virtual void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
{
MessageHead head = new MessageHead(actionGetter.GetMsgId(), actionGetter.GetActionId(), errorCode, errorInfo);
MessageStructure sb = new MessageStructure();
sb.WriteBuffer(head);
response.BinaryWrite(sb.PopBuffer());
}
示例3: SuccessCallback
protected override void SuccessCallback(MessageStructure writer, MessageHead head)
{
int type = writer.ReadInt();
if (type == 1)
{
int recordCount = writer.ReadInt();
JsonObject jsonContainer = new JsonObject();
List<JsonObject> jsonList = new List<JsonObject>();
for (int i = 0; i < recordCount; i++)
{
writer.RecordStart();
var item = new JsonObject();
item.Add("NoticeID", writer.ReadString());
item.Add("Title", writer.ReadString());
item.Add("Content", writer.ReadString());
item.Add("IsBroadcast", writer.ReadInt());
item.Add("IsTop", writer.ReadInt());
item.Add("Creater", writer.ReadString());
item.Add("CreateDate", writer.ReadString());
item.Add("ExpiryDate", writer.ReadString());
jsonList.Add(item);
writer.RecordEnd();
}
jsonContainer.Add("total", recordCount);
jsonContainer.Add("rows", jsonList.ToArray());
WriteTableJson(jsonContainer);
}
}
示例4: OnReceiveTimeout
public override void OnReceiveTimeout(string clientAddress, byte[] receiveData)
{
try
{
BufferReader reader = new BufferReader(receiveData);
string paramString = reader.ReadPacketString();
paramString = HttpUtility.UrlDecode(paramString, Encoding.UTF8);
int index = paramString.IndexOf("?d=");
if (index != -1)
{
index += 3;
paramString = paramString.Substring(index, paramString.Length - index);
}
PacketMessage receivePacket = ParsePacketMessage(clientAddress, paramString, ConnectType.Tcp);
var recHead = receivePacket.Head;
int errorCode = LanguageHelper.GetLang().ErrorCode;
string errorMsg = LanguageHelper.GetLang().RequestTimeout;
MessageHead head = new MessageHead(recHead.MsgId, recHead.ActionId, "st", errorCode, errorMsg);
head.HasGzip = true;
MessageStructure ds = new MessageStructure();
ds.WriteBuffer(head);
byte[] data = ds.ReadBuffer();
OnSendCompleted(clientAddress, data);
}
catch (Exception ex)
{
TraceLog.WriteError("Send to client {0} timeout error:{1}", clientAddress, ex);
}
}
示例5: Create
public static MessageStructure Create(string serverUrl, string requestParams, out MessageHead header, bool isSocket)
{
header = null;
MessageStructure msgReader = null;
if (isSocket)
{
msgReader = DoRequest(serverUrl, requestParams);
}
else
{
Encoding encode = Encoding.GetEncoding("utf-8");
string postData = "d=" + GetSign(requestParams);
byte[] bufferData = encode.GetBytes(postData);
HttpWebRequest serverRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
serverRequest.Method = "POST";
serverRequest.ContentType = "application/x-www-form-urlencoded";
serverRequest.ContentLength = bufferData.Length;
Stream requestStream = serverRequest.GetRequestStream();
requestStream.Write(bufferData, 0, bufferData.Length);
requestStream.Close();
//������
WebResponse serverResponse = serverRequest.GetResponse();
Stream responseStream = serverResponse.GetResponseStream();
msgReader = MessageStructure.Create(responseStream, Encoding.UTF8);
}
if (msgReader != null)
{
header = msgReader.ReadHeadGzip();
}
return msgReader;
}
示例6: CtorErrMsg
public static byte[] CtorErrMsg(int error, string msg, NameValueCollection requestParam)
{
int msgId = Convert.ToInt32(requestParam["msgid"]);
int actionid = Convert.ToInt32(requestParam["actionid"]);
var ms = new MessageStructure();
var head = new MessageHead(msgId, actionid, "st", error, msg);
ms.WriteBuffer(head);
return ms.PosGzipBuffer();
}
示例7: DecodePacket
protected override bool DecodePacket(MessageStructure reader, MessageHead head)
{
responsePack = ProtoBufUtils.Deserialize<Response1003Pack>(netReader.Buffer);
string responseDataInfo = "";
responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Request1003Pack>(req) + "\n";
responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<Response1003Pack>(responsePack) + "\n";
DecodePacketInfo = responseDataInfo;
return true;
}
示例8: DecodePacket
protected override bool DecodePacket(MessageStructure reader, MessageHead head)
{
_session.Context.SessionId = reader.ReadString();
_session.Context.UserId = reader.ReadString().ToInt();
int UserType = reader.ReadInt();
string LoginTime = reader.ReadString();
int GuideID = reader.ReadInt();
if (GuideID == 1005)
{
SetChildStep("1005");
}
return true;
}
示例9: DecodePacket
protected override bool DecodePacket(MessageStructure reader, MessageHead head)
{
responsePack = ProtoBufUtils.Deserialize<ResponsePack>(netReader.Buffer);
string responseDataInfo = "";
responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Request1000Pack>(req) + "\n";
responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<ResponsePack>(responsePack) + "\n";
DecodePacketInfo = responseDataInfo;
int childStepId = getChild(1000);
if(childStepId>0)
{
System.Collections.Generic.Dictionary<string,string> dic = new System.Collections.Generic.Dictionary<string,string>();
dic.Add("UserID",responsePack.UserID.ToString()) ;
SetChildStep(childStepId.ToString(),_setting,dic);
}
return true;
}
示例10: DecodePacket
protected override bool DecodePacket(MessageStructure reader, MessageHead head)
{
try
{
responsePack = ProtoBufUtils.Deserialize<Action3000Response>(netReader.Buffer);
string responseDataInfo = "";
responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Action3000Request>(req) + "\n";
responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<Action3000Response>(responsePack) + "\n";
DecodePacketInfo = responseDataInfo;
}
catch (System.Exception e)
{
System.Console.WriteLine(e.Message);
}
return true;
}
示例11: RequestTimeout
public void RequestTimeout(HttpConnection connection)
{
var param = connection.Param;
int msgId = param.Get("MsgId").ToInt();
int actionId = param.Get("ActionId").ToInt();
int errorCode = LanguageHelper.GetLang().ErrorCode;
string errorMsg = LanguageHelper.GetLang().RequestTimeout;
var head = new MessageHead(msgId, actionId, "st", errorCode, errorMsg);
head.HasGzip = true;
var ms = new MessageStructure();
ms.WriteBuffer(head);
byte[] data = ms.ReadBuffer();
string remoteAddress = connection.Context.Request.RemoteEndPoint.Address.ToString();
string successMsg = string.Format("{0}>>发送超时到{1} {2}字节!",
DateTime.Now.ToString("HH:mm:ss:ms"), remoteAddress, data.Length);
Console.WriteLine(successMsg);
OnResponseCompleted(connection, data);
}
示例12: DecodePacket
protected override bool DecodePacket(MessageStructure reader, MessageHead head)
{
responsePack = ProtoBufUtils.Deserialize<ResponsePack>(netReader.Buffer);
string responseDataInfo = "";
responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Request2000Pack>(req) + "\n";
responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<ResponsePack>(responsePack) + "\n";
DecodePacketInfo = responseDataInfo;
int childStepId = getChild(2000);
System.Console.WriteLine("childStepID:"+childStepId);
if (childStepId > 0)
{
System.Collections.Generic.Dictionary<string, string> dic = new System.Collections.Generic.Dictionary<string, string>();
/*
req.token = GetParamsData("token",req.token);
req.typeUser = GetParamsData("typeUser",req.typeUser);
req.version = GetParamsData("version", req.version);
req.UserID = GetParamsData("UserID", req.UserID);
*/
SetChildStep(childStepId.ToString(),_setting,dic);
}
return true;
}
示例13: WriteBuffer
/// <summary>
/// 将缓冲队列写入缓冲区,大于10k开始压缩
/// </summary>
/// <param name="head"></param>
public void WriteBuffer(MessageHead head)
{
int stackSize = GetHeadByteSize(head);
stackSize += GetStackByteSize();//包括了头部长度大小
head.TotalLength = stackSize;
bool hasGzipHead = false;
if (head.HasGzip && (!EnableGzip || (EnableGzip && stackSize <= EnableGzipMinByte)))
{
hasGzipHead = true;
head.GzipLength = stackSize;
WriteByte(head.GzipLength);
}
//输出总字节长度,公式: stackSize = len(头) + len(内容) + 4(int)
WriteByte(stackSize);
WriteHeadBufer(head);
WriteStackToBuffer();
//判断是否有启用Gzip
if (head.HasGzip && EnableGzip && !hasGzipHead && stackSize > EnableGzipMinByte)
{
byte[] orgData = PopBuffer();
head.GzipLength = WriteGzipCompressBuffer(orgData);
}
head.PacketLength = Length;
Reset();
}
示例14: ReadHeadGzip
/// <summary>
/// 读取消息头,如果有Gzip压缩时自动解压字节流
/// </summary>
/// <returns></returns>
/// <exception cref="OverflowException"></exception>
public MessageHead ReadHeadGzip()
{
try
{
MessageHead head = new MessageHead();
head.HasGzip = true;
head.PacketLength = Length;
if (CheckGzipBuffer())
{
byte[] gzipData = PopBuffer();
head.GzipLength = gzipData.Length;
//gzip格式500+gzip( 1000+ XXXXXX)
byte[] deZipData = GzipUtils.DeCompress(gzipData, 0, gzipData.Length);
WriteByte(deZipData);
Reset();
}
head.TotalLength = ReadInt();
head.ErrorCode = ReadInt();
head.MsgId = ReadInt();
head.ErrorInfo = ReadString();
head.Action = ReadInt();
head.St = ReadString();
return head;
}
catch (Exception ex)
{
string error = string.Format("read to {0}/{1}pos error,\r\nbytes:{2}", Offset, Length, ToHexString());
throw new OverflowException(error, ex);
}
}
示例15: ReadHead
/// <summary>
/// 读取消息头
/// </summary>
/// <returns></returns>
public MessageHead ReadHead()
{
MessageHead head = new MessageHead();
head.PacketLength = Length;
head.TotalLength = ReadInt();
head.ErrorCode = ReadInt();
head.MsgId = ReadInt();
head.ErrorInfo = ReadString();
head.Action = ReadInt();
head.St = ReadString();
return head;
}