0

I'm trying to send a python file to a Bluetooth device using 32feet.net and it throws this error. I have revised it so now it makes an attempt to send but times out and fails.

System.Net.WebException: Connect failed. ---> System.Net.Sockets.SocketException: The requested address is not valid in its context A0AB51BE1948:0000110500001000800000805f9b34fb
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.Connect(BluetoothEndPoint remoteEP)
at InTheHand.Net.Sockets.BluetoothClient.Connect(BluetoothEndPoint remoteEP)
at InTheHand.Net.ObexWebRequest.Connect()
at InTheHand.Net.ObexWebRequest.GetResponse()
--- End of inner exception stack trace ---
at InTheHand.Net.ObexWebRequest.GetResponse()
at Bluetooth_DualSense.Form1.SendFile(String fileToSend, String destinationPath) in C:\Users\timmy\source\repos\Bluetooth DualSense\Bluetooth DualSense\Form1.cs:line 89

Here is my code.

public void SendFile(string fileToSend, string destinationPath)
{
    string macAddr = "A0AB51BE1948";
    var address = BluetoothAddress.Parse(macAddr);
    try
    {
        var obexUri = new Uri("obex://" + address + "/" + destinationPath);
        var request = new ObexWebRequest(obexUri);
        request.ReadFile(fileToSend);
        var response = request.GetResponse() as ObexWebResponse;
        response.Close();
    }
    catch (FileNotFoundException e)
    {
        textBox1.Text += Environment.NewLine + "||||ERROR||||"+ Environment.NewLine + "No Script Found";
        textBox1.Text += Environment.NewLine + "File Created Called: " + e.FileName;
            File.Create(e.FileName);
    }
    catch (Exception ex)
    {
        textBox1.Text += Environment.NewLine+ex;
    }      
}

And to call...

SendFile("FileName.py", Directory.GetCurrentDirectory());
Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
Bender
  • 3
  • 3
  • You can not use colon separator in the address of device while crating URL. https://inthehand.github.io/html/M_InTheHand_Net_ObexWebRequest__ctor_2.htm – Chetan Feb 28 '21 at 03:24
  • You create an instance of `BluetoothAddress` class by doing `var address = BluetoothAddress.Parse(macAddr);` and then use is to create ObexWebRequest by doing `var request = new ObexWebRequest(address, destinationPath);` – Chetan Feb 28 '21 at 03:28
  • @ChetanRanpariya I no longer have the colon separator, but now I get a(n) UriFormatException: Scheme type not supported by ObexWebRequest. `string mac = "A0AB51BE1948"; var address = BluetoothAddress.Parse(mac); try { var request = new ObexWebRequest(address, destinationPath); request.ReadFile(fileToSend); var response = request.GetResponse() as ObexWebResponse; response.Close(); }` – Bender Feb 28 '21 at 04:39
  • Can you edit the original question add the new code and new error message details there? Did you face the same issue when using colon in the address? why did you choose not to use colon? – Chetan Feb 28 '21 at 04:43
  • @ChetanRanpariya I changed the original post. If I put the colon in now after your suggestion I still get the same error. I chose not to use the colon because you posted a link to there documentation stating that you cant have a colon in the address. – Bender Feb 28 '21 at 05:14
  • In your updated code you created `var address = ` but you not using it correctly.. .. the code you shared in comment and code in the question are different... – Chetan Feb 28 '21 at 06:29
  • Yes, I changed it after @ChetanRanpariya asked me to, I did not include `var address = BluetoothAddress.Parse(addr);` because I have it set outside of the try/catch block. – Bender Feb 28 '21 at 06:55

0 Answers0