示例#1
0
        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);
        }
示例#2
0
        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);
                    });
                }
            }
        }