private static void ReceiveCallback(SocketClient socketClient, Action <string> received) { var buffer = new byte[1048]; // 接收消息 var receiveNumber = socketClient.AcceptSocket.Receive(buffer); if (receiveNumber <= 0) { return; } buffer = buffer.Skip(0).Take(receiveNumber).ToArray(); var result = HexHelper.ByteToHexStr(buffer); received(result); }
public static void SendMessage(this SocketClient socketClient, string message) { if (socketClient.AcceptSocket == null) { return; } var data = HexHelper.HexStrToByte(message); try { socketClient.AcceptSocket.Send(data); } catch (Exception ex) { if (!socketClient.AcceptSocket.Connected) { Accept(socketClient, () => { socketClient.AcceptSocket.Send(data); }); } } }