12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Net.Sockets;
- namespace SuperSocket.Common
- {
-
-
-
- public static class SocketEx
- {
-
-
-
-
- public static void SafeClose(this Socket socket)
- {
- if (socket == null)
- return;
- if (!socket.Connected)
- return;
-
- try
- {
- socket.Shutdown(SocketShutdown.Both);
- }
- catch
- {
- }
- try
- {
- socket.Close();
- }
- catch
- {
- }
- }
-
-
-
-
-
- public static void SendData(this Socket client, byte[] data)
- {
- SendData(client, data, 0, data.Length);
- }
-
-
-
-
-
-
-
- public static void SendData(this Socket client, byte[] data, int offset, int length)
- {
- int sent = 0;
- int thisSent = 0;
- while ((length - sent) > 0)
- {
- thisSent = client.Send(data, offset + sent, length - sent, SocketFlags.None);
- sent += thisSent;
- }
- }
- }
- }
|