Ejemplo n.º 1
0
 /// <summary>
 /// 启动SOCKET服务
 /// </summary>
 public void Start()
 {
     try
     {
         Buffer = new BufferManage(MaxListen, BufferSize);
         Server.Listen(MaxListen);
         ListenEvent?.Invoke(null, new ListenEventArgs {
             Message = Server.LocalEndPoint.ToString()
         });
         StartAccept(null);
     }
     catch (Exception e)
     {
         Log.WriteLog(e.TargetSite + "->" + e.Message, LogType.ERROR);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 关闭SOCKET服务
 /// </summary>
 public void Close()
 {
     try
     {
         Server.Shutdown(SocketShutdown.Both);
         Server.Close();
         Server.Dispose();
     }catch { }
     foreach (var item in _dic.Values)
     {
         try
         {
             item.Client.Shutdown(SocketShutdown.Both);
             item.Client.Close();
             item.Client.Dispose();
         }
         catch { }
     }
     _dic.Clear();
     _argsDic.Clear();
     Buffer = null;
 }