我一直在努力理解这个 VB 代码,我正在尝试构建一个使用蓝牙连接进行通信的应用程序,谁能帮我将 ti 转换为 C#,以便我能正确理解它。
' The host part of the URI is the device address, e.g. IrDAAddress.ToString(),
' and the file part is the OBEX object name.
Dim addr As String = "112233445566"
Dim uri As New Uri("obex://" & addr & "/HelloWorld.txt")
Dim req As New ObexWebRequest(uri)
req.ReadFile("Hello World.txt")
Dim rsp As ObexWebResponse = CType(req.GetResponse(),ObexWebResponse)
Console.WriteLine("Response Code: {0} (0x{0:X})", rsp.StatusCode)
' The host part of the URI is the device address, e.g. IrDAAddress.ToString(),
' and the file part is the OBEX object name.
Dim addr As String = "112233445566"
Dim uri As New Uri("obex://" & addr & "/HelloWorld2.txt")
Dim req As New ObexWebRequest(uri)
Using content As Stream = req.GetRequestStream()
' Using a StreamWriter to write text to the stream...
Using wtr As New StreamWriter(content)
wtr.WriteLine("Hello World GetRequestStream")
wtr.WriteLine("Hello World GetRequestStream 2")
wtr.Flush()
' Set the Length header value
req.ContentLength = content.Length
End Using
' In this case closing the StreamWriter also closed the Stream, but ...
End Using
Dim rsp As ObexWebResponse = CType(req.GetResponse(),ObexWebResponse)
Console.WriteLine("Response Code: {0} (0x{0:X})", rsp.StatusCode)
Dim lsnr As New ObexListener(ObexTransport. Bluetooth)
lsnr.Start()
' For each connection
Dim ctx As ObexListenerContext = lsnr.GetContext()
Dim req As ObexListenerRequest = ctx.Request
Dim pathSplits() As String = req.RawUrl.Split('/')
Dim filename As String = pathSplits(pathSplits.Length – 1)
req.WriteFile(filename)
'
lsnr.Stop()
Dim addr As BluetoothAddress _
= BluetoothAddress.Parse("001122334455")
'
Dim ep As New BluetoothEndPoint(addr, BluetoothService.SerialPort)
Dim cli As New BluetoothClient
cli.Connect(ep)
Dim peerStream As Stream = cli.GetStream()
peerStream.Write/Read ...
提前致谢!