本文整理汇总了C#中ZyGames.Framework.RPC.Sockets.ConnectionEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionEventArgs类的具体用法?C# ConnectionEventArgs怎么用?C# ConnectionEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionEventArgs类属于ZyGames.Framework.RPC.Sockets命名空间,在下文中一共展示了ConnectionEventArgs类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: OnDataReceived
private void OnDataReceived(ConnectionEventArgs e)
{
if (DataReceived != null)
{
DataReceived(this, e);
}
}
开发者ID:lvshiling,项目名称:Scut,代码行数:7,代码来源:SocketListener.cs
示例2: OnHandshaked
private void OnHandshaked(ConnectionEventArgs e)
{
if (Handshaked != null)
{
Handshaked(this, e);
}
}
开发者ID:lvshiling,项目名称:Scut,代码行数:7,代码来源:SocketListener.cs
示例3: OnDisconnected
private void OnDisconnected(ConnectionEventArgs e)
{
if (Disconnected != null)
{
Disconnected(this, e);
}
}
开发者ID:lvshiling,项目名称:Scut,代码行数:7,代码来源:SocketListener.cs
示例4: OnConnected
private void OnConnected(ConnectionEventArgs e)
{
if (Connected != null)
{
Connected(this, e);
}
}
开发者ID:lvshiling,项目名称:Scut,代码行数:7,代码来源:SocketListener.cs
示例5: TryDecodePackage
/// <summary>
/// Decode request package
/// </summary>
/// <param name="e"></param>
/// <param name="package"></param>
/// <returns></returns>
public bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package)
{
package = null;
string paramStr = Encoding.ASCII.GetString(e.Data);
int index = paramStr.IndexOf("?d=", StringComparison.CurrentCultureIgnoreCase);
string routeName = string.Empty;
if (index != -1)
{
if (paramStr.StartsWith("route:", StringComparison.CurrentCultureIgnoreCase))
{
routeName = paramStr.Substring(6, index - 6);
}
paramStr = paramStr.Substring(index, paramStr.Length - index);
paramStr = HttpUtility.ParseQueryString(paramStr)["d"];
}
var nvc = HttpUtility.ParseQueryString(paramStr);
var param = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
foreach (var key in nvc.AllKeys)
{
param[key] = nvc[key];
}
if (param.ContainsKey("route"))
{
routeName = param["route"];
}
//if (!param.ContainsKey("ssid")) { Interlocked.Increment(ref errorDropNum); return; }
if (!param.ContainsKey("actionid")) { return false; }
if (!param.ContainsKey("msgid")) { return false; }
//sessionId of proxy server
Guid proxySid;
if (!param.ContainsKey("ssid") || !Guid.TryParse(param["ssid"], out proxySid))
{
proxySid = Guid.Empty;
}
int actionid;
if (!int.TryParse(param["actionid"], out actionid)) { return false; }
int msgid;
if (!int.TryParse(param["msgid"], out msgid)) { return false; }
int userId;
int.TryParse(param["uid"], out userId);
string sessionId = param.ContainsKey("sid") ? param["sid"] : "";
package = new RequestPackage(msgid, sessionId, actionid, userId)
{
ProxySid = proxySid,
IsProxyRequest = param.ContainsKey("isproxy"),
RouteName = routeName,
IsUrlParam = true,
UrlParam = paramStr
};
return true;
}
开发者ID:kehaoran74,项目名称:Scut,代码行数:62,代码来源:ActionDispatcher.cs
示例6: OnConnectCompleted
protected override void OnConnectCompleted(object sender, ConnectionEventArgs e)
{
string address = e.Socket.RemoteEndPoint.ToString();
if (!_sessions.ContainsKey(address))
{
var user = new GuestUser();
user.Init();
_sessions[address] = user;
}
}
开发者ID:Jachon,项目名称:Scut,代码行数:10,代码来源:GameHostApp.cs
示例7: TryDecodePackage
public bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package)
{
//这里解出头部信息根据ActionId来分发请求到相应的Action子类
package = null;
byte[] content;
MessagePack head = ReadMessageHead(e.Data, out content);
if (head == null)
{
return false;
}
package = new RequestPackage(head.MsgId, head.SessionId, head.ActionId, head.UserId) { Message = content };
return true;
}
开发者ID:daneric,项目名称:Scut-samples,代码行数:14,代码来源:CustomActionDispatcher.cs
示例8: TryDecodePackage
public bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package)
{
//这里解出头部信息根据ActionId来分发请求到相应的Action子类
package = null;
byte[] content;
//todo test 1001 action
//MessagePack packageHead = new MessagePack { MsgId = 1, ActionId = 1001, SessionId = "", UserId = 1380001 };
//byte[] headBytes = ProtoBufUtils.Serialize(packageHead);
//byte[] contentBytes = ProtoBufUtils.Serialize(new Request1001Pack() { PageIndex = 1, PageSize = 20 });
//e.Data = BufferUtils.MergeBytes(BufferUtils.AppendHeadBytes(headBytes), contentBytes);
MessagePack head = ReadMessageHead(e.Data, out content);
if (head == null)
{
return false;
}
package = new RequestPackage(head.MsgId, head.SessionId, head.ActionId, head.UserId) { Message = content };
return true;
}
开发者ID:jinfei426,项目名称:Scut,代码行数:20,代码来源:CustomActionDispatcher.cs
示例9: socketLintener_Disconnected
void socketLintener_Disconnected(object sender, ConnectionEventArgs e)
{
try
{
ClientConnection clientConnection;
if (clientConnections.TryGetValue(e.Socket, out clientConnection))
{
clientConnections.Remove(clientConnection.SSID);
TraceLog.ReleaseWriteDebug("断开 IP:{0},ssid:{1}", clientConnection.Socket.RemoteEndPoint, clientConnection.SSID);
if (clientConnection.ServerId != 0)
{
NameValueCollection requestParam = new NameValueCollection();
requestParam["actionid"] = ((int)ActionEnum.Interrupt).ToString();
requestParam["ssid"] = clientConnection.SSID.ToString("N");
requestParam["msgid"] = "0";
string paramStr = RequestParse.ToQueryString(requestParam);
byte[] paramData = Encoding.ASCII.GetBytes(paramStr);
try
{
gsConnectionManager.Send(clientConnection.GameId, clientConnection.ServerId, paramData);
}
catch (Exception ex)
{
TraceLog.WriteError("Send to tcp disconnected notify failed:{0}\r\nparam:{1}", ex, paramStr);
}
}
}
else
{
TraceLog.ReleaseWriteDebug("断开 IP:{0}。", e.Socket.RemoteEndPoint);
}
}
catch (Exception err)
{
TraceLog.WriteError("Disconnected:{0}", err);
}
}
开发者ID:houguohua,项目名称:Scut,代码行数:38,代码来源:SocketProxy.cs
示例10: socketLintener_DataReceived
private void socketLintener_DataReceived(object sender, ConnectionEventArgs e)
{
try
{
Interlocked.Increment(ref receiveNum);
OnReceivedBefore(e);
RequestPackage package;
if (!ActionDispatcher.TryDecodePackage(e, out package))
{
return;
}
var session = GetSession(e, package);
if (CheckSpecialPackge(package, session))
{
return;
}
package.Session = session;
package.ReceiveTime = DateTime.Now;
requestQueue.Enqueue(package);
singal.Set();
}
catch (Exception ex)
{
TraceLog.WriteError("Received to Host:{0} error:{1}", e.Socket.RemoteEndPoint, ex);
}
}
开发者ID:JohnnyXq,项目名称:Scut,代码行数:26,代码来源:GameSocketHost.cs
示例11: socketLintener_Disconnected
private void socketLintener_Disconnected(object sender, ConnectionEventArgs e)
{
try
{
GameSession session = GameSession.Get(e.Socket.HashCode);
if (session != null)
{
OnDisconnected(session);
session.ProxySid = Guid.Empty;
session.Close();
}
}
catch (Exception err)
{
TraceLog.WriteError("Disconnected error:{0}", err);
}
}
开发者ID:JohnnyXq,项目名称:Scut,代码行数:17,代码来源:GameSocketHost.cs
示例12: OnReceivedBefore
/// <summary>
/// Raises the received before event.
/// </summary>
/// <param name="e">E.</param>
protected virtual void OnReceivedBefore(ConnectionEventArgs e)
{
}
开发者ID:JohnnyXq,项目名称:Scut,代码行数:7,代码来源:GameSocketHost.cs
示例13: GetSession
private GameSession GetSession(ConnectionEventArgs e, RequestPackage package)
{
//使用代理分发器时,每个ssid建立一个游服Serssion
GameSession session;
if (package.ProxySid != Guid.Empty)
{
session = GameSession.Get(package.ProxySid) ??
(package.IsProxyRequest
? GameSession.Get(e.Socket.HashCode)
: GameSession.CreateNew(package.ProxySid, e.Socket, socketLintener.PostSend));
if (session != null)
{
session.ProxySid = package.ProxySid;
}
}
else
{
session = GameSession.Get(package.SessionId) ?? GameSession.Get(e.Socket.HashCode);
}
if (session != null && !session.Connected)
{
GameSession.Recover(session, e.Socket.HashCode, e.Socket, socketLintener.PostSend);
}
return session;
}
开发者ID:JohnnyXq,项目名称:Scut,代码行数:25,代码来源:GameSocketHost.cs
示例14: socketLintener_DataReceived
void socketLintener_DataReceived(object sender, ConnectionEventArgs e)
{
var data = Encoding.ASCII.GetString(e.Data);
try
{
string routeName = string.Empty;
int index = data.LastIndexOf("?d=");
if (index > 0)
{
if (data.StartsWith("route:", StringComparison.CurrentCultureIgnoreCase))
{
routeName = data.Substring(6, index - 6);
}
data = data.Substring(index, data.Length - index);
}
data = HttpUtility.ParseQueryString(data)["d"];
int gameId, serverId, statuscode;
var ip = e.Socket.RemoteEndPoint.ToString().Split(new char[] { ':' })[0];
var requestParam = RequestParse.Parse(ip, "", data, out gameId, out serverId, out statuscode);
if (statuscode != (int)HttpStatusCode.OK)
{// 接收到非法数据
listener.CloseSocket(e.Socket);
return;
}
ClientConnection clientConnection;
if (!clientConnections.TryGetValue(e.Socket, out clientConnection))
{
TraceLog.WriteError("接收到不在连接池中的socket数据,哪里有bug。");
listener.CloseSocket(e.Socket);
return;
}
if (clientConnection.GameId == 0) clientConnection.GameId = gameId;
if (clientConnection.ServerId == 0) clientConnection.ServerId = serverId;
requestParam["UserHostAddress"] = ip;
requestParam["ssid"] = clientConnection.SSID.ToString("N");
requestParam["http"] = "0";
string paramStr = string.Format("{0}&UserHostAddress={1}&ssid={2}&http=0",
data,
ip,
requestParam["ssid"]);
if (!string.IsNullOrEmpty(routeName))
{
requestParam["route"] = routeName;
paramStr += "&route=" + routeName;
}
byte[] paramData = Encoding.ASCII.GetBytes(paramStr);
try
{
if (!gsConnectionManager.Send(gameId, serverId, paramData))
{
var responseData = RequestParse.CtorErrMsg(10000, RequestParse.ErrorMsgConnectFail, requestParam);
SendDataBack(clientConnection.SSID, responseData, 0, responseData.Length);
}
}
catch (Exception ex)
{
TraceLog.WriteError("无法连接游服error:{0}\r\nparam:{1}", ex, paramStr);
var responseData = RequestParse.CtorErrMsg(10000, RequestParse.ErrorMsgConnectFail, requestParam);
SendDataBack(clientConnection.SSID, responseData, 0, responseData.Length);
}
}
catch (Exception err)
{
TraceLog.WriteError("DataReceived error:{0},param:{1}", err, data);
}
}
开发者ID:houguohua,项目名称:Scut,代码行数:70,代码来源:SocketProxy.cs
示例15: OnError
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnError(ISocket sender, ConnectionEventArgs e)
{
sender.CloseHandshake(e.Socket, "param error");
}
开发者ID:huangbenyu,项目名称:Scut,代码行数:9,代码来源:GameWebSocketHost.cs
示例16: OnError
protected override void OnError(ISocket sender, ConnectionEventArgs e)
{
Console.WriteLine("Server send to {0} data error.", e.Socket.RemoteEndPoint);
base.OnError(sender, e);
}
开发者ID:daneric,项目名称:Scut-samples,代码行数:5,代码来源:MainClass.cs
示例17: OnReceivedBefore
protected override void OnReceivedBefore(ConnectionEventArgs e)
{
//Console.WriteLine("Url:{0}", Encoding.ASCII.GetString(e.Data));
}
开发者ID:0jpq0,项目名称:Scut,代码行数:4,代码来源:GameHostApp.cs
示例18: TryDecodePackage
/// <summary>
/// Decode request package
/// </summary>
/// <param name="e"></param>
/// <param name="package"></param>
/// <returns></returns>
public virtual bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package)
{
var packageReader = new PackageReader(e.Data, Encoding.UTF8);
if (TryBuildPackage(packageReader, out package))
{
package.OpCode = e.Meaage.OpCode;
package.CommandMessage = e.Socket.IsWebSocket && e.Meaage.OpCode == OpCode.Text
? e.Meaage.Message
: null;
return true;
}
return false;
}
开发者ID:lvshiling,项目名称:Scut,代码行数:19,代码来源:ActionDispatcher.cs
示例19: OnPong
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnPong(ISocket sender, ConnectionEventArgs e)
{
}
开发者ID:huangbenyu,项目名称:Scut,代码行数:8,代码来源:GameWebSocketHost.cs
示例20: GetSession
private GameSession GetSession(ConnectionEventArgs e, RequestPackage package)
{
//使用代理分发器时,每个ssid建立一个游服Serssion
GameSession session;
if (package.ProxySid != Guid.Empty)
{
session = GameSession.Get(package.ProxySid) ??
(package.IsProxyRequest
? GameSession.Get(e.Socket.HashCode)
: GameSession.CreateNew(package.ProxySid, e.Socket, socketListener));
if (session != null)
{
session.ProxySid = package.ProxySid;
}
}
else
{
session = GameSession.Get(package.SessionId) ?? GameSession.Get(e.Socket.HashCode);
}
if (session == null)
{
session = GameSession.CreateNew(package.ProxySid, e.Socket, socketListener);
}
if ((!session.Connected || !Equals(session.RemoteAddress, e.Socket.RemoteEndPoint.ToString())))
{
GameSession.Recover(session, e.Socket.HashCode, e.Socket, socketListener);
}
return session;
}
开发者ID:yunjoker,项目名称:Scut,代码行数:29,代码来源:GameSocketHost.cs
注:本文中的ZyGames.Framework.RPC.Sockets.ConnectionEventArgs类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论