public Message CreateBinaryMessage() { byte[] messageDataBytes = null; var webSockectMsgType = WebSocketMessageType.Binary; switch (MessageType) { case MessageType.JointPosition: messageDataBytes = JointsDataBytes; break; case MessageType.HandPosition: _handsDataBytes[0] = (byte)MessageType; Buffer.BlockCopy(BitConverter.GetBytes(LeftHand.Item1), 0, _handsDataBytes, 1, 4); Buffer.BlockCopy(BitConverter.GetBytes(LeftHand.Item2), 0, _handsDataBytes, 5, 4); Buffer.BlockCopy(BitConverter.GetBytes(RightHand.Item1), 0, _handsDataBytes, 9, 4); Buffer.BlockCopy(BitConverter.GetBytes(RightHand.Item2), 0, _handsDataBytes, 13, 4); messageDataBytes = _handsDataBytes; break; case MessageType.DepthJpeg: messageDataBytes = JpegBytes; break; case MessageType.DepthArray: //var sizeInBytes = 2 * DepthDataArray.Length; //messageDataBytes = new byte[sizeInBytes]; //Buffer.BlockCopy(DepthDataArray, 0, messageDataBytes, 0, sizeInBytes); messageDataBytes = DepthDataArray; break; case MessageType.Information: webSockectMsgType = WebSocketMessageType.Text; var bCount = Encoding.UTF8.GetByteCount(Data); messageDataBytes = new byte[1 + bCount]; messageDataBytes[0] = (byte)MessageType; Buffer.BlockCopy(Encoding.UTF8.GetBytes(Data), 0, messageDataBytes, 1, Encoding.UTF8.GetByteCount(Data)); break; } if (messageDataBytes == null) { return(null); } Message msg = ByteStreamMessage.CreateMessage( new ArraySegment <byte>(messageDataBytes)); msg.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = webSockectMsgType, }; return(msg); }
private Message CreateByteArrayMessage(string txt) { Message msg = ByteStreamMessage.CreateMessage(new ArraySegment <byte>(Encoding.UTF8.GetBytes(txt))); msg.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = WebSocketMessageType.Text }; return(msg); }
public Message CreateMessage(byte[] msgBytes) { Message msg = ByteStreamMessage.CreateMessage(new ArraySegment <byte>(msgBytes)); msg.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = WebSocketMessageType.Text }; return(msg); }
/// <summary> /// 广播消息 /// </summary> /// <param name="data">消息内容</param> /// <returns></returns> public Task Broadcast(byte[] data) { Message message = ByteStreamMessage.CreateMessage(new ArraySegment <byte>(data)); message.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = WebSocketMessageType.Binary }; return(this.Broadcast(message)); }
/// <summary> /// 广播消息 /// </summary> /// <param name="value">消息内容</param> /// <returns></returns> public Task Broadcast(string value) { Message message = ByteStreamMessage.CreateMessage(new ArraySegment <byte>(Encoding.UTF8.GetBytes(value))); message.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = WebSocketMessageType.Text }; return(this.Broadcast(message)); }
public static Message CreateMessage(this byte[] message, WebSocketMessageType messageType = WebSocketMessageType.Text) { var result = ByteStreamMessage.CreateMessage(new ArraySegment <byte>(message)); result.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = messageType }; return(result); }
private Message CreateMessage(byte[] message, WebSocketMessageType type = WebSocketMessageType.Binary) { Message channelMessage = ByteStreamMessage.CreateMessage(new ArraySegment <byte>(message)); channelMessage.Properties[Service.webSocketMessageProperty] = new WebSocketMessageProperty { MessageType = type }; return(channelMessage); }
private System.ServiceModel.Channels.Message CreateMessage(string msgText) { System.ServiceModel.Channels.Message msg = ByteStreamMessage.CreateMessage( new ArraySegment <byte>(Encoding.UTF8.GetBytes(msgText))); msg.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = WebSocketMessageType.Text }; return(msg); }
private Message CreateMessage(string content) { Message message = ByteStreamMessage.CreateMessage( new ArraySegment <byte>( Encoding.UTF8.GetBytes(content))); message.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = WebSocketMessageType.Text }; return(message); }
/// <summary> /// 发送消息 /// </summary> /// <param name="value"></param> /// <returns></returns> public async Task Send(string value) { if (this.disposed) { throw new ObjectDisposedException(base.GetType().FullName); } Message message = ByteStreamMessage.CreateMessage(new ArraySegment <byte>(Encoding.UTF8.GetBytes(value))); message.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = WebSocketMessageType.Text }; await this.Callback.OnMessage(message); }
public Message CreateStreamResponse(Stream stream, string contentType) { if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream"); } if (contentType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contentType"); } Message message = ByteStreamMessage.CreateMessage(stream); message.Properties.Add(WebBodyFormatMessageProperty.Name, WebBodyFormatMessageProperty.RawProperty); AddContentType(contentType, null); return(message); }
internal static Message CreateMessage(this MessageBase message, byte[] messageDataBytes, WebSocketMessageType webSockectMsgType) { byte[] payload = new byte[messageTypeSize + messageDataBytes.Length]; payload[0] = (byte)message.Type; Buffer.BlockCopy(messageDataBytes, 0, payload, 1, messageDataBytes.Length); Message msg = ByteStreamMessage.CreateMessage( new ArraySegment <byte>(payload)); msg.Properties["WebSocketMessageProperty"] = new WebSocketMessageProperty { MessageType = webSockectMsgType }; return(msg); }
Message CreateMessageFromStream(object data) { Message result; if (data == null) { result = Message.CreateMessage(MessageVersion.None, (string)null); } else { Stream streamData = data as Stream; if (streamData == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR2.GetString(SR2.ParameterIsNotStreamType, data.GetType(), this.operationName, this.contractName, this.contractNs))); } result = ByteStreamMessage.CreateMessage(streamData); result.Properties[WebBodyFormatMessageProperty.Name] = WebBodyFormatMessageProperty.RawProperty; } return(result); }