本文整理汇总了C#中Socket.SafeClose方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.SafeClose方法的具体用法?C# Socket.SafeClose怎么用?C# Socket.SafeClose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.SafeClose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartReceive
/// <summary>
/// 第1次接收到数据
/// </summary>
/// <param name="client"></param>
/// <param name="bin"></param>
protected virtual void StartReceive(Socket client, byte[] buffer, int offset, int count)
{
ISession session = m_sessionFactory.CreateSession(client);
if (session != null)
{
session.ReceiveAsync(buffer, offset, count);
}
else
{
client.SafeClose();
}
}
示例2: CheckError
static void CheckError(Socket socket, Dictionary<Socket, RConClient> socketToObject)
{
string addr = "<address lost>";
RConClient rcon = null;
if (socketToObject.ContainsKey(socket))
{
rcon = socketToObject[socket];
addr = rcon.remoteAddress;
}
try
{
addr = socket.RemoteEndPoint.ToString();
}
catch (Exception) { }
try
{
socket.Receive(errorBuf);
ProgramLog.Admin.Log("{0}: remote console connection closed", rcon.Id);
}
catch (Exception e)
{
HandleSocketException(e);
ProgramLog.Admin.Log("{0}: remote console connection closed", rcon.Id);
}
socket.SafeClose();
}
示例3: InternalClose
private void InternalClose(Socket client, CloseReason reason, bool setCloseReason)
{
if (Interlocked.CompareExchange(ref m_Client, null, client) == client)
{
if (setCloseReason)
AddStateFlag(GetCloseReasonValue(reason));
client.SafeClose();
if (ValidateNotInSendingReceiving())
{
OnClosed(reason);
}
}
}
示例4: AcceptClient
static bool AcceptClient(Socket client)
{
client.NoDelay = true;
string addr;
try
{
var rep = client.RemoteEndPoint;
if (rep != null)
addr = rep.ToString();
else
{
ProgramLog.Debug.Log ("Accepted socket disconnected");
return false;
}
}
catch (Exception e)
{
ProgramLog.Debug.Log ("Accepted socket exception ({0})", HandleSocketException (e));
return false;
}
try
{
ProgramLog.Users.Log ("{0} is connecting...", addr);
var conn = new Networking.ClientConnection (client, -1); //ignore the warning
}
catch (SocketException)
{
client.SafeClose ();
ProgramLog.Users.Log ("{0} disconnected.", addr);
}
return true;
}
示例5: CheckError
static void CheckError(Socket socket, Dictionary<Socket, int> socketToId)
{
string addr = "<address lost>";
int id = -1;
if (socketToId.ContainsKey (socket))
{
id = socketToId[socket];
addr = slots[id].remoteAddress;
}
try
{
addr = socket.RemoteEndPoint.ToString();
}
catch (Exception) {}
try
{
socket.Receive (errorBuf);
if (id >= 0)
Program.tConsole.WriteLine ("{0} @ {1}: connection closed", addr, id);
else
Program.tConsole.WriteLine ("{0}: connection closed", addr);
}
catch (Exception e)
{
HandleSocketException (e);
if (id >= 0)
Program.tConsole.WriteLine ("{0} @ {1}: connection closed", addr, id);
else
Program.tConsole.WriteLine ("{0}: connection closed", addr);
}
socket.SafeClose ();
}
示例6: AcceptClient
static int AcceptClient(Socket client)
{
client.NoDelay = true;
string addr;
try
{
var rep = client.RemoteEndPoint;
if (rep != null)
addr = rep.ToString();
else
{
Program.tConsole.WriteLine ("Accepted socket disconnected");
return -1;
}
}
catch (Exception e)
{
Program.tConsole.WriteLine ("Accepted socket exception ({1})", HandleSocketException (e));
return -1;
}
for (int i = 0; i < 255; i++)
{
int k = (lastId + i) % 255;
if (slots[k].state == SlotState.VACANT)
{
lastId = k;
Program.tConsole.WriteLine ("{0} is connecting on slot {1}...", addr, k);
try
{
AcceptSlot (k, client, addr);
}
catch (SocketException)
{
client.SafeClose ();
Program.tConsole.WriteLine ("{0} disconnected.", addr);
return -1;
}
return k;
}
}
client.SafeClose ();
Program.tConsole.WriteLine ("{0} dropped, no slots left.", addr);
return -1;
}
示例7: SocketDisconnecter
public SocketDisconnecter(Socket sock, int closeAfter = 1000)
{
_socket = sock;
var tmr = new Timer((sender) =>
{
try
{
var tm = sender as Timer;
tm.Dispose();
_socket.SafeClose();
}
catch { }
this.Dispose();
});
tmr.Change(closeAfter, closeAfter);
}
示例8: AcceptClient
static int AcceptClient(Socket client)
{
client.NoDelay = true;
string addr;
try
{
var rep = client.RemoteEndPoint;
if (rep != null)
addr = rep.ToString();
else
{
ProgramLog.Debug.Log ("Accepted socket disconnected");
return -1;
}
}
catch (Exception e)
{
ProgramLog.Debug.Log ("Accepted socket exception ({0})", HandleSocketException (e));
return -1;
}
for (int i = 0; i < 255; i++)
{
if (slots[i].state == SlotState.VACANT)
{
ProgramLog.Users.Log ("{0} is connecting on slot {1}...", addr, i);
try
{
AcceptSlot (i, client, addr);
}
catch (SocketException)
{
client.SafeClose ();
ProgramLog.Users.Log ("{0} disconnected.", addr);
return -1;
}
return i;
}
}
client.SafeClose ();
ProgramLog.Users.Log ("{0} dropped, no slots left.", addr);
return -1;
}
示例9: ProcessConnect
/// <summary>
/// 连接事件
/// </summary>
/// <param name="e"></param>
protected override void ProcessConnect(Socket client, SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
lock (m_sockets)
{
m_sockets.Add(client);
}
try
{
var hander = ConnecteSuccess;
if (hander != null)
{
hander(this, e);
}
OnConnected(client);
}
catch
{
lock (m_sockets)
{
m_sockets.Remove(client);
}
client.SafeClose();
}
}
else
{
var hander = ConnecteFail;
if (hander != null)
{
hander(this, e);
}
}
}