123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- namespace Utilities
- {
- public class SocketUtils
- {
-
-
-
- public static void ReleaseSocket(Socket socket)
- {
- if (socket != null)
- {
- if (socket.Connected)
- {
- try
- {
- socket.Shutdown(SocketShutdown.Both);
- socket.Disconnect(false);
- }
- catch (ObjectDisposedException)
- {
- return;
- }
- catch (SocketException)
- { }
- }
- socket.Close();
- socket = null;
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- }
- }
- }
|