public async Task BroadcastMessageAsync(OicMessage request) { var message = request.ToCoapMessage(); message.IsMulticast = true; message.Type = CoapMessageType.NonConfirmable; await _client.SendAsync(message); }
public async Task <int> SendMessageAsync(OicMessage request, IOicEndpoint endpoint = null) { var coapEndpoint = endpoint as OicCoapEndpoint ?? throw new ArgumentException($"{nameof(endpoint)} is not of type {nameof(OicCoapEndpoint)}", nameof(endpoint)); var message = request.ToCoapMessage(); var baseRequest = message.Clone(); baseRequest.Payload = null; _requestMessages.Add(request.RequestId, baseRequest); return((await _client.SendAsync(message, coapEndpoint._coapEndpoint)).Id); }
public static CoapMessage ToCoapMessage(this OicMessage message) { var coapMessage = new CoapMessage { Payload = message.Content, Token = BitConverter.GetBytes(message.RequestId), }; if (message.ContentType != OicMessageContentType.None) { coapMessage.Options.Add(new CoAPNet.Options.ContentFormat(message.ContentType.ToCoapContentFormat())); } if (message.ToUri != null) { if (message.ToUri.IsAbsoluteUri) { coapMessage.SetUri(new UriBuilder(message.ToUri) { Scheme = "coap" }.Uri); } else { coapMessage.SetUri(message.ToUri, UriComponents.PathAndQuery); } } if (message is OicRequest request) { coapMessage.Code = request.Operation.ToCoapMessageCode(); foreach (var contentType in request.Accepts) { coapMessage.Options.Add(new CoAPNet.Options.Accept(contentType.ToCoapContentFormat())); } } else if (message is OicResponse response) { coapMessage.Code = response.ResposeCode.ToCoapMessageCode(); } return(coapMessage); }
public virtual Task BroadcastMessageAsync(OicMessage message) { return(Task.CompletedTask); }
public virtual Task <int> MockSendMessageAsync(OicMessage packet) { return(Task.FromResult(0)); }
public Task <int> SendMessageAsync(OicMessage message, IOicEndpoint endpoint = null) { return(IsDisposed ? throw new OicException("Encdpoint Disposed") : MockSendMessageAsync(message)); }