本文整理汇总了C#中ZyGames.Framework.RPC.IO.MessageStructure.PopBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# MessageStructure.PopBuffer方法的具体用法?C# MessageStructure.PopBuffer怎么用?C# MessageStructure.PopBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZyGames.Framework.RPC.IO.MessageStructure
的用法示例。
在下文中一共展示了MessageStructure.PopBuffer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
/// <summary>
///
/// </summary>
/// <param name="package"></param>
/// <param name="param"></param>
/// <returns></returns>
public byte[] ProcessRequest(object package, object param)
{
var httpresponse = new SocketGameResponse();
ActionGetter actionGetter = null;
try
{
httpresponse.WriteErrorCallback += new ScutActionDispatcher().ResponseError;
RequestPackage p = package as RequestPackage;
actionGetter = param as ActionGetter;
if (!string.IsNullOrEmpty(p.RouteName))
{
if (CheckRemote(p.RouteName, actionGetter))
{
MessageStructure response = new MessageStructure();
OnCallRemote(p.RouteName, actionGetter, response);
return response.PopBuffer();
}
httpresponse.WriteError(actionGetter, 10000, "No permission");
}
else
{
DoAction(actionGetter, httpresponse);
}
return httpresponse.ReadByte();
}
catch (Exception ex)
{
TraceLog.WriteError("Request error:{0}", ex);
MessageStructure response = new MessageStructure();
response.WriteBuffer(new MessageHead(0, 10000, "request error"));
return response.PopBuffer();
}
}
示例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: ProcessPackage
private void ProcessPackage(object state)
{
var package = (RequestPackage)state;
if (package == null) return;
var session = package.Session;
try
{
byte[] data = new byte[0];
if (!string.IsNullOrEmpty(package.RouteName))
{
HttpGet httpGet = new HttpGet(package);
if (CheckRemote(package.RouteName, httpGet))
{
MessageStructure response = new MessageStructure();
OnCallRemote(package.RouteName, httpGet, response);
data = response.PopBuffer();
}
}
else
{
SocketGameResponse response = new SocketGameResponse();
response.WriteErrorCallback += ActionDispatcher.ResponseError;
ActionGetter actionGetter = ActionDispatcher.GetActionGetter(package);
OnRequested(actionGetter, response);
data = response.ReadByte();
}
try
{
if (data.Length > 0)
{
session.SendAsync(data, 0, data.Length);
}
}
catch (Exception ex)
{
TraceLog.WriteError("PostSend异常{0}", ex);
}
}
catch (Exception ex)
{
TraceLog.WriteError("Task异常{0}", ex);
}
finally
{
session.ExitSession();
Interlocked.Decrement(ref runningNum);
}
}
示例4: OnHttpRequest
private void OnHttpRequest(IAsyncResult result)
{
try
{
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);
listener.BeginGetContext(OnHttpRequest, listener);
RequestPackage package;
if (!ActionDispatcher.TryDecodePackage(context, out package))
{
return;
}
GameSession session;
if (package.ProxySid != Guid.Empty)
{
session = GameSession.Get(package.ProxySid) ?? GameSession.CreateNew(package.ProxySid, context.Request);
session.ProxySid = package.ProxySid;
}
else
{
session = (string.IsNullOrEmpty(package.SessionId)
? GameSession.GetSessionByCookie(context.Request)
: GameSession.Get(package.SessionId))
?? GameSession.CreateNew(Guid.NewGuid(), context.Request);
}
package.Bind(session);
ActionGetter httpGet = ActionDispatcher.GetActionGetter(package, session);
if (package.IsUrlParam)
{
httpGet["UserHostAddress"] = session.RemoteAddress;
httpGet["ssid"] = session.KeyCode.ToString("N");
httpGet["http"] = "1";
}
//set cookie
var cookie = context.Request.Cookies["sid"];
if (cookie == null)
{
cookie = new Cookie("sid", session.SessionId);
cookie.Expires = DateTime.Now.AddMinutes(5);
context.Response.SetCookie(cookie);
}
var httpresponse = new SocketGameResponse();
httpresponse.WriteErrorCallback += new ScutActionDispatcher().ResponseError;
var clientConnection = new HttpClientConnection
{
Context = context,
Session = session,
ActionGetter = httpGet,
GameResponse = httpresponse
};
var section = GetSection();
clientConnection.TimeoutTimer = new Timer(OnHttpRequestTimeout, clientConnection, section.HttpRequestTimeout, Timeout.Infinite);
byte[] respData = new byte[0];
if (!string.IsNullOrEmpty(package.RouteName))
{
if (CheckRemote(package.RouteName, httpGet))
{
MessageStructure response = new MessageStructure();
OnCallRemote(package.RouteName, httpGet, response);
respData = response.PopBuffer();
}
}
else
{
DoAction(httpGet, httpresponse);
respData = httpresponse.ReadByte();
}
OnHttpResponse(clientConnection, respData, 0, respData.Length);
}
catch (Exception ex)
{
TraceLog.WriteError("OnHttpRequest error:{0}", ex);
}
}
示例5: ResponseHearbeat
/// <summary>
/// Response hearbeat stream.
/// </summary>
/// <param name="package"></param>
/// <param name="session"></param>
protected void ResponseHearbeat(RequestPackage package, GameSession session)
{
try
{
MessageStructure response = new MessageStructure();
response.WriteBuffer(new MessageHead(package.MsgId, package.ActionId, 0));
var data = response.PopBuffer();
if (session != null && data.Length > 0)
{
session.SendAsync(OpCode.Binary, data, 0, data.Length, OnSendCompleted).Wait();
}
}
catch (Exception ex)
{
TraceLog.WriteError("Post Heartbeat error:{0}", ex);
}
}
示例6: ProcessPackage
private async System.Threading.Tasks.Task ProcessPackage(RequestPackage package, GameSession session)
{
if (package == null) return;
try
{
ActionGetter actionGetter;
byte[] data = new byte[0];
if (!string.IsNullOrEmpty(package.RouteName))
{
actionGetter = ActionDispatcher.GetActionGetter(package, session);
if (CheckRemote(package.RouteName, actionGetter))
{
MessageStructure response = new MessageStructure();
OnCallRemote(package.RouteName, actionGetter, response);
data = response.PopBuffer();
}
else
{
return;
}
}
else
{
SocketGameResponse response = new SocketGameResponse();
response.WriteErrorCallback += ActionDispatcher.ResponseError;
actionGetter = ActionDispatcher.GetActionGetter(package, session);
DoAction(actionGetter, response);
data = response.ReadByte();
}
try
{
if (session != null && data.Length > 0)
{
await session.SendAsync(actionGetter.OpCode, data, 0, data.Length, OnSendCompleted);
}
}
catch (Exception ex)
{
TraceLog.WriteError("PostSend error:{0}", ex);
}
}
catch (Exception ex)
{
TraceLog.WriteError("Task error:{0}", ex);
}
finally
{
if (session != null) session.ExitSession();
}
}
示例7: ProcessPackage
private void ProcessPackage(object state)
{
var package = (RequestPackage)state;
if (package == null) return;
var param = package.Param;
var session = package.Session;
var actionid = package.ActionId;
try
{
if (actionid == (int)ActionEnum.Heartbeat)
{
// 客户端tcp心跳包
session.LastActivityTime = DateTime.Now;
OnHeartbeat(session);
session.ExitSession();
Interlocked.Decrement(ref runningNum);
return;
}
HttpGet httpGet = new HttpGet(param, session);
byte[] data = new byte[0];
if (!string.IsNullOrEmpty(package.Route))
{
if (CheckRemote(package.Route, httpGet))
{
MessageStructure response = new MessageStructure();
OnCallRemote(package.Route, httpGet, response);
data = response.PopBuffer();
}
}
else
{
SocketGameResponse response = new SocketGameResponse();
OnRequested(httpGet, response);
data = response.ReadByte();
}
try
{
session.SendAsync(data, 0, data.Length);
}
catch (Exception ex)
{
TraceLog.WriteError("PostSend异常{0}", ex);
}
}
catch (Exception ex)
{
TraceLog.WriteError("Task异常{0}", ex);
}
finally
{
session.ExitSession();
Interlocked.Decrement(ref runningNum);
}
}
示例8: DoSerialize
private static byte[] DoSerialize(params BaseEntity[] entityList)
{
var rootWriter = new MessageStructure();
rootWriter.PushIntoStack(entityList.Length);
object fieldValue = null;
foreach (var entity in entityList)
{
var schema = entity.GetSchema();
if (schema == null)
{
continue;
}
var recordWriter = new MessageStructure();
recordWriter.PushIntoStack(schema.EntityName);
//write columns
var columns = schema.GetColumns();
foreach (var column in columns)
{
fieldValue = entity.GetPropertyValue(column.Name);
if (EntitySchemaSet.IsSupportType(column.ColumnType))
{
recordWriter.PushIntoStack(column.ColumnType, fieldValue);
}
else if (column.HasChild)
{
PushChildStack(recordWriter, column, fieldValue);
}
}
rootWriter.PushIntoStack(recordWriter);
}
var head = new MessageHead(SyncActionId);
rootWriter.WriteBuffer(head);
return rootWriter.PopBuffer();
}
示例9: ResponseError
/// <summary>
///
/// </summary>
/// <param name="response"></param>
/// <param name="actionGetter"></param>
/// <param name="errorCode"></param>
/// <param name="errorInfo"></param>
public virtual void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
{
string st = actionGetter.GetSt();
ProtocolVersion prtcl = actionGetter.GetPtcl();
MessageHead head = new MessageHead(actionGetter.GetMsgId(), actionGetter.GetActionId(), st, errorCode, errorInfo);
MessageStructure sb = new MessageStructure();
if (prtcl >= ProtocolVersion.ExtendHead)
{
sb.PushIntoStack(0); //不输出扩展头属性
}
sb.WriteBuffer(head);
response.BinaryWrite(sb.PopBuffer());
}