Brecham.Obex — An OBEX library for the .NET Framework

ObexPduFactory.CreateRequest Method (Byte[], ObexOpcode, ObexHeaderCollection, Stream)

[This is preliminary documentation and subject to change.]

Create a request PDU, and validity checks the resultant PDU.

[Visual Basic]
Overloads Public Function CreateRequest( _
   ByVal buffer As Byte(), _
   ByVal opcode As ObexOpcode, _
   ByVal headers As ObexHeaderCollection, _
   ByVal bodyStream As Stream _
) As ObexCreatedPdu
[C#]
public ObexCreatedPdu CreateRequest(
   byte[] buffer,
   ObexOpcode opcode,
   ObexHeaderCollection headers,
   Stream bodyStream
);

Parameters

buffer
See Create.
opcode
The opcode to include in the PDU, as an ObexOpcode.
headers
See Create.
bodyStream
See Create.

Return Value

See Create.

Remarks

The response code specified can be any valid code; either Final (the ‘final’ bit set), or non-Final if the code is valid as non-final, but see below.

If creating a Connect PDU the extra Connect bytes will be added, they define the protocol version in use and the maximum packet size. The latter is as set at initialisation with bufferSize, or subsequently with LocalMru.

If the all headers do no fit within the maximum PDU size then as with Create any unincluded headers remain if the header collection. In that case we also assume that the remaining headers will be sent in the folowing PDU and thus we clear the final bit in the opcode. That also is done if a body header type was added with content from the bodyStream.

The PDU and its opcode are then checked for validity. Only certain opcodes can be non-final ie PUT and GET. CONNECT for instance cannot. See OBEX13.pdf sections 3.3 and 3.1. If the opcode is invalid then ProtocolViolationException is thrown.

If sending a PDU that cannot have its headers split across PDUs then the caller should handle that case externally, as it can know what to do in that case. For instance when sending an Abort or Disconnect, ObexClientSession will at first attempt to include the reason text string but if that fails then it tries again but without the string header. There are thus two exceptions that can occur on the headers being too long: ProtocolViolationException as described here, and ObexCreateTooLongException is even the first header would not fit, see Create. aaaa Create.

Exceptions

Exception TypeCondition
ProtocolViolationException If the response code in invalid, see above.
For other possible exceptions see Create.

See Also

ObexPduFactory Class | Brecham.Obex.Pdus Namespace | ObexPduFactory.CreateRequest Overload List