当前位置: 首页>>代码示例>>C#>>正文


C# Socket.SafeClose方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:abel,项目名称:sinan,代码行数:17,代码来源:AsyncTcpListener.cs

示例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();
        }
开发者ID:VanixxGraphix,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:30,代码来源:RConServer.cs

示例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);
                }
            }
        }
开发者ID:kerryjiang,项目名称:SuperSocket,代码行数:15,代码来源:SocketSession.cs

示例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;
        }
开发者ID:jocull,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:35,代码来源:NetPlay.cs

示例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 ();
        }
开发者ID:alexcassol,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:36,代码来源:NetPlay.cs

示例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;
        }
开发者ID:alexcassol,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:51,代码来源:NetPlay.cs

示例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);
            }
开发者ID:VanixxGraphix,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:18,代码来源:Server.cs

示例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;
        }
开发者ID:CaptainMuscles,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:49,代码来源:NetPlay.cs

示例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);
         }
     }
 }
开发者ID:abel,项目名称:sinan,代码行数:39,代码来源:AsyncTcpClient.cs


注:本文中的Socket.SafeClose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。