A client-side connection to an OBEX server, supports Put, Get, and most other operation types.
For a list of all members of this type, see ObexClientSession Members.
System.Object
Brecham.Obex.ObexClientSession
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Every operation that communicates with the peer OBEX server can throw a variety of exceptions, they are: IOException, ObexResponseException, and ProtocolViolationException. The first of course occurs if the network connection fails, and thus the OBEX connection is no longer usable. The second occurs if the server returns an error response code to a particular operation. In many cases this is not a terminal condition and more operations can be attempted subsequently. For instance a GET for a particular named object can fail in this way (hopefully) with response code NotFound if the requested object does not exist. There is no need to close the connection at this point another operation can then be attempted. Finally ProtocolViolationException occurs when the format of the OBEX packet received from the peer is invalid. In that case it is not possible to know what state the connection is in, so the connection should be closed.
A simple example of sending a file is included below.
[Visual Basic]
Option Strict On
Option Explicit On
Imports System
Imports System.IO 'e.g. FileStream, File, etc.
Imports Brecham.Obex
Imports InTheHand.Net 'e.g. IrDAEndPoint
Imports InTheHand.Net.Sockets 'e.g. IrDAClient
' Available from http://32feet.net/.
Class VbPutSampleSample
Public Shared Sub Main(ByVal args() As String)
' Open file as selected by the user
If args.Length <> 1 Then
Console.WriteLine("No filename given.")
Exit Sub
End If
Dim filename As String = args(0)
Using srcFile As FileStream = File.OpenRead(filename)
' Connect
Dim cli As New IrDAClient("OBEX")
Dim sess As New ObexClientSession(cli.GetStream, 4096)
sess.Connect()
' And Send
Dim name As String = Path.GetFilename(filename)
Dim contentLength As Int64 = srcFile.Length
sess.PutFrom(srcFile, name, Nothing, contentLength)
cli.Close()
End Using
End Sub
End Class
Namespace: Brecham.Obex
Assembly: Brecham.Obex (in Brecham.Obex.dll)
ObexClientSession Members | Brecham.Obex Namespace