本文整理汇总了C#中ZyGames.Framework.RPC.Sockets.ExSocket类的典型用法代码示例。如果您正苦于以下问题:C# ExSocket类的具体用法?C# ExSocket怎么用?C# ExSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExSocket类属于ZyGames.Framework.RPC.Sockets命名空间,在下文中一共展示了ExSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseHandshake
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="reason"></param>
public override void CloseHandshake(ExSocket socket, string reason)
{
Dispose(socket, OpCode.Close, reason);
}
示例2: GameSession
private GameSession(Guid sid, ExSocket exSocket, Action<ExSocket, byte[], int, int> sendCallback)
: this(sid, null)
{
InitSocket(exSocket, sendCallback);
//添加_remoteAddress 设置,方便打印远程地址 [3/25/2014 lsx]
_remoteAddress = exSocket.RemoteEndPoint.ToString();
}
示例3: Recover
/// <summary>
/// Recover session
/// </summary>
/// <param name="session"></param>
/// <param name="newSessionKey"></param>
/// <param name="socket"></param>
/// <param name="sendCallback"></param>
/// <returns></returns>
public static void Recover(GameSession session, Guid newSessionKey, ExSocket socket, Action<ExSocket, byte[], int, int> sendCallback)
{
var newSession = Get(newSessionKey);
if (session != null &&
newSession != null &&
session != newSession)
{
session._exSocket = socket;
session._sendCallback = sendCallback;
GameSession temp;
_globalSession.TryRemove(newSessionKey, out temp);
}
}
示例4: PostSend
/// <summary>
/// Posts the send.
/// </summary>
/// <param name="socket">Socket.</param>
/// <param name="data">Data.</param>
/// <param name="offset">Offset.</param>
/// <param name="count">Count.</param>
public void PostSend(ExSocket socket, byte[] data, int offset, int count)
{
byte[] buffer = new byte[count + 4];
Buffer.BlockCopy(BitConverter.GetBytes(count), 0, buffer, 0, 4);
Buffer.BlockCopy(data, offset, buffer, 4, count);
socket.Enqueue(buffer);
if (socket.TrySetSendFlag())
{
try
{
TryDequeueAndPostSend(socket, null);
}
catch
{
socket.ResetSendFlag();
throw;
}
}
}
示例5: ProcessAccept
private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs)
{
PostAccept();
if (acceptEventArgs.SocketError != SocketError.Success)
{
HandleBadAccept(acceptEventArgs);
return;
}
SocketAsyncEventArgs ioEventArgs = this.ioEventArgsPool.Pop();
ioEventArgs.AcceptSocket = acceptEventArgs.AcceptSocket;
acceptEventArgs.AcceptSocket = null;
this.acceptEventArgsPool.Push(acceptEventArgs);
var dataToken = (DataToken)ioEventArgs.UserToken;
ioEventArgs.SetBuffer(dataToken.bufferOffset, socketSettings.BufferSize);
var exSocket = new ExSocket(ioEventArgs.AcceptSocket);
exSocket.LastAccessTime = DateTime.Now;
dataToken.Socket = exSocket;
AddClient(exSocket);
try
{
OnConnected(new ConnectionEventArgs { Socket = exSocket });
}
catch (Exception ex)
{
TraceLog.WriteError("OnConnected error:{0}", ex);
}
PostReceive(ioEventArgs);
}
示例6: SendMessage
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="message"></param>
/// <param name="encoding"></param>
/// <param name="callback"></param>
public void SendMessage(ExSocket socket, string message, Encoding encoding, Action<SocketAsyncResult> callback)
{
byte[] buffer = encoding.GetBytes(message);
SendMessage(socket, buffer, callback);
}
示例7: OnClosedStatus
protected override void OnClosedStatus(ExSocket socket, int closeStatusCode)
{
Console.WriteLine("Receive client {0} close status code {1}.", socket.RemoteEndPoint, closeStatusCode);
}
示例8: PostSend
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="opCode"></param>
/// <param name="data"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
public override async Task PostSend(ExSocket socket, sbyte opCode, byte[] data, int offset, int count)
{
await PostSend(socket, opCode, data, offset, count, result => { });
}
示例9: TryDequeueAndPostSend
private void TryDequeueAndPostSend(ExSocket socket, SocketAsyncEventArgs ioEventArgs)
{
bool isOwner = ioEventArgs == null;
SocketAsyncResult result;
if (socket.TryDequeue(out result))
{
if (ioEventArgs == null)
{
ioEventArgs = ioEventArgsPool.Pop();
ioEventArgs.AcceptSocket = socket.WorkSocket;
}
DataToken dataToken = (DataToken)ioEventArgs.UserToken;
dataToken.Socket = socket;
dataToken.AsyncResult = result;
dataToken.byteArrayForMessage = result.Data;
dataToken.messageLength = result.Data.Length;
try
{
PostSend(ioEventArgs);
}
catch (Exception ex)
{
dataToken.ResultCallback(ResultCode.Error, ex);
if (isOwner)
ReleaseIOEventArgs(ioEventArgs);
socket.ResetSendFlag();
}
}
else
{
ReleaseIOEventArgs(ioEventArgs);
socket.ResetSendFlag();
}
}
示例10: DoClosedStatus
private void DoClosedStatus(ExSocket socket, int statusCode)
{
Action<ExSocket, int> handler = OnClosedStatus;
if (handler != null) handler(socket, statusCode);
}
示例11: ProcessAccept
private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs)
{
try
{
Interlocked.Increment(ref _summaryStatus.TotalConnectCount);
maxConnectionsEnforcer.WaitOne();
if (acceptEventArgs.SocketError != SocketError.Success)
{
Interlocked.Increment(ref _summaryStatus.RejectedConnectCount);
HandleBadAccept(acceptEventArgs);
}
else
{
Interlocked.Increment(ref _summaryStatus.CurrentConnectCount);
SocketAsyncEventArgs ioEventArgs = this.ioEventArgsPool.Pop();
ioEventArgs.AcceptSocket = acceptEventArgs.AcceptSocket;
var dataToken = (DataToken)ioEventArgs.UserToken;
ioEventArgs.SetBuffer(dataToken.bufferOffset, socketSettings.BufferSize);
var exSocket = new ExSocket(ioEventArgs.AcceptSocket);
exSocket.LastAccessTime = DateTime.Now;
dataToken.Socket = exSocket;
acceptEventArgs.AcceptSocket = null;
//release connect when socket has be closed.
ReleaseAccept(acceptEventArgs, false);
try
{
OnConnected(new ConnectionEventArgs { Socket = exSocket });
}
catch (Exception ex)
{
TraceLog.WriteError("OnConnected error:{0}", ex);
}
PostReceive(ioEventArgs);
}
}
finally
{
PostAccept();
}
}
示例12: Dispose
/// <summary>
///
/// </summary>
/// <param name="exSocket"></param>
/// <param name="opCode"></param>
/// <param name="reason"></param>
protected void Dispose(ExSocket exSocket, sbyte opCode, string reason)
{
try
{
var e = new SocketEventArgs()
{
Socket = exSocket,
Source = new DataMeaage() { OpCode = opCode, Message = reason }
};
DoClosed(e);
OnDisconnected(e);
if (exSocket != null) exSocket.Close();
}
catch (Exception ex)
{
TraceLog.WriteError("Dispose connect of client error:{0}", ex);
}
}
示例13: OnClosedStatus
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="closeStatusCode"></param>
protected virtual void OnClosedStatus(ExSocket socket, int closeStatusCode)
{
}
示例14: Pong
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
public override void Pong(ExSocket socket)
{
byte[] data = Encoding.UTF8.GetBytes("pong");
PostSend(socket, OpCode.Pong, data, 0, data.Length).Wait();
}
示例15: SendCloseHandshake
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="opCode"></param>
/// <param name="reason"></param>
public virtual void SendCloseHandshake(ExSocket socket, sbyte opCode, string reason)
{
if (MessageProcessor != null)
{
byte[] data = MessageProcessor.CloseMessage(socket, opCode, reason);
if (data != null) AppServer.SendAsync(socket, data, result => { });
}
}