本文整理汇总了C#中Request.RemoveOptions方法的典型用法代码示例。如果您正苦于以下问题:C# Request.RemoveOptions方法的具体用法?C# Request.RemoveOptions怎么用?C# Request.RemoveOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request.RemoveOptions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformObserve
//send observe request
private void PerformObserve(Request.Method method, Uri uri)
{
if (null != _currentRequest)
_currentRequest.Cancel();
Request request = Request.Create(method);
_currentRequest = request;
request.URI = uri;
request.AddOption(Option.Create(OptionType.Observe, 60));
request.Token = TokenManager.Instance.AcquireToken(false);
request.Responded += new EventHandler<ResponseEventArgs>(observe_Responded);
_observingRequest = request;
//try Websocket connect
try
{
//wait for websocket connect
Thread.Sleep(5000);
observedSession = coapWebSocektService.SessionList[coapWebSocektService.SessionList.Count - 1];
request.ResponseQueueEnabled = true;
request.Execute();
}
catch
{
_observingRequest.RemoveOptions(OptionType.Observe);
_observingRequest.Execute();
_observingRequest = null;
Console.WriteLine("Bad websocket connect");
this.clientSocket.Send(Encoding.UTF8.GetBytes("Bad websocket connect"));
this.clientSocket.Disconnect(false);
this.clientSocket.Dispose();
}
}
示例2: ReceiveResponse
/// <inheritdoc/>
public override void ReceiveResponse(INextLayer nextLayer, Exchange exchange, Response response)
{
if (!response.HasOption(OptionType.Block1) && !response.HasOption(OptionType.Block2))
{
// There is no block1 or block2 option, therefore it is a normal response
exchange.Response = response;
base.ReceiveResponse(nextLayer, exchange, response);
return;
}
BlockOption block1 = response.Block1;
if (block1 != null)
{
// TODO: What if request has not been sent blockwise (server error)
if (log.IsDebugEnabled)
log.Debug("Response acknowledges block " + block1);
BlockwiseStatus status = exchange.RequestBlockStatus;
if (!status.Complete)
{
// TODO: the response code should be CONTINUE. Otherwise deliver
// Send next block
Int32 currentSize = 1 << (4 + status.CurrentSZX);
Int32 nextNum = status.CurrentNUM + currentSize / block1.Size;
if (log.IsDebugEnabled)
log.Debug("Send next block num = " + nextNum);
status.CurrentNUM = nextNum;
status.CurrentSZX = block1.SZX;
Request nextBlock = GetNextRequestBlock(exchange.Request, status);
if (nextBlock.Token == null)
nextBlock.Token = response.Token; // reuse same token
exchange.CurrentRequest = nextBlock;
base.SendRequest(nextLayer, exchange, nextBlock);
// do not deliver response
}
else if (!response.HasOption(OptionType.Block2))
{
// All request block have been acknowledged and we receive a piggy-backed
// response that needs no blockwise transfer. Thus, deliver it.
base.ReceiveResponse(nextLayer, exchange, response);
}
else
{
if (log.IsDebugEnabled)
log.Debug("Response has Block2 option and is therefore sent blockwise");
}
}
BlockOption block2 = response.Block2;
if (block2 != null)
{
BlockwiseStatus status = FindResponseBlockStatus(exchange, response);
if (block2.NUM == status.CurrentNUM)
{
// We got the block we expected :-)
status.AddBlock(response.Payload);
Int32? obs = response.Observe;
if (obs.HasValue)
status.Observe = obs.Value;
// notify blocking progress
exchange.Request.FireResponding(response);
if (status.IsRandomAccess)
{
// The client has requested this specifc block and we deliver it
exchange.Response = response;
base.ReceiveResponse(nextLayer, exchange, response);
}
else if (block2.M)
{
if (log.IsDebugEnabled)
log.Debug("Request the next response block");
// TODO: If this is a notification, do we have to use
// another token now?
Request request = exchange.Request;
Int32 num = block2.NUM + 1;
Int32 szx = block2.SZX;
Boolean m = false;
Request block = new Request(request.Method);
block.Token = response.Token;
block.SetOptions(request.GetOptions());
block.Destination = request.Destination;
block.Type = request.Type; // NON could make sense over SMS or similar transports
block.SetOption(new BlockOption(OptionType.Block2, num, szx, m));
status.CurrentNUM = num;
// to make it easier for Observe, we do not re-use the Token
//if (!response.HasOption(OptionType.Observe))
//{
// block.Token = request.Token;
//}
// make sure not to use Observe for block retrieval
block.RemoveOptions(OptionType.Observe);
//.........这里部分代码省略.........
示例3: ForwardRequest
protected override Response ForwardRequest(Request incomingRequest)
{
// check the invariant: the request must have the proxy-uri set
if (!incomingRequest.HasOption(OptionType.ProxyUri))
{
if (log.IsWarnEnabled)
log.Warn("Proxy-uri option not set.");
return new Response(StatusCode.BadOption);
}
// remove the fake uri-path
// FIXME: HACK
incomingRequest.RemoveOptions(OptionType.UriPath);
// create a new request to forward to the requested coap server
Request outgoingRequest = null;
try
{
outgoingRequest = CoapTranslator.GetRequest(incomingRequest);
//outgoingRequest.ResponseQueueEnabled = true;
//outgoingRequest.Token = TokenManager.Instance.AcquireToken();
outgoingRequest.Send();
}
catch (TranslationException ex)
{
if (log.IsWarnEnabled)
log.Warn("Proxy-uri option malformed: " + ex.Message);
return new Response(StatusCode.BadOption);
}
catch (System.IO.IOException ex)
{
if (log.IsWarnEnabled)
log.Warn("Failed to execute request: " + ex.Message);
return new Response(StatusCode.InternalServerError);
}
// receive the response
Response receivedResponse = null;
try
{
receivedResponse = outgoingRequest.WaitForResponse();
}
catch (System.Threading.ThreadInterruptedException ex)
{
if (log.IsWarnEnabled)
log.Warn("Receiving of response interrupted: " + ex.Message);
return new Response(StatusCode.InternalServerError);
}
if (receivedResponse == null)
{
return new Response(StatusCode.GatewayTimeout);
}
else
{
// create the real response for the original request
Response outgoingResponse = CoapTranslator.GetResponse(receivedResponse);
return outgoingResponse;
}
}