Resolved 32feet.NET send file using Obex URI

ty bender

New member
Joined
Feb 28, 2021
Messages
2
Programming Experience
Beginner
I try sending a file using 32feet.Net's Obex library and I get an System.Net.Sockets.SocketException. I have not been able to find any relevant examples and the current documentation is outdated.

Here is my full Exception
System.Net.WebException: Connect failed. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 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 function to send it.


Sendfile:
public void SendFile(string fileToSend, string destinationPath)
        {
            string addr = "A0AB51BE1948";
            var address = BluetoothAddress.Parse(addr);
            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)
            {
                DialogResult result = MessageBox.Show("Exception thrown: Ex9076\nDo you wish to take actions to resolve this ERROR?", "ERROR", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    textBox1.Text += Environment.NewLine + "Downloading...  " + e.FileName;
                    textBox1.Text += Environment.NewLine + "Downloaded";
                    File.Create(e.FileName);
                }
                else
                {
                    textBox1.Text = "";
                    for ( int i = 0; i < 10; i++)
                    {
                        textBox1.Text += "MISSING: " + e.FileName+ Environment.NewLine;
                    }
                }
            }
            catch (Exception ex)
            {
                textBox1.Text += Environment.NewLine+ex;
            }
            
        }


and, to call...
Call Script:
SendFile("doyouknowpython.py", Directory.GetCurrentDirectory());
 
Firstly, welcome to the forums.

Second, why are you using a dated API who's docs are out of date?

I am sure there are other modern up-to-date libraries you can use for Bluetooth file sending.

Thirdly, why are you not using a UriBuilder properly?

This :
var obexUri = new Uri("obex://" + address + "/" + destinationPath);
Is not how you build up a Uri.

You should further note that Bluetooth pairing needs to take place before any parsing can be done. Otherwise, I'd expect nothing more than an exception. So I'd recommend you start there.
 
I try sending a file using 32feet.Net's Obex library and I get an System.Net.Sockets.SocketException. I have not been able to find any relevant examples and the current documentation is outdated.

Here is my full Exception
System.Net.WebException: Connect failed. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 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 function to send it.


Sendfile:
public void SendFile(string fileToSend, string destinationPath)
        {
            string addr = "A0AB51BE1948";
            var address = BluetoothAddress.Parse(addr);
            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)
            {
                DialogResult result = MessageBox.Show("Exception thrown: Ex9076\nDo you wish to take actions to resolve this ERROR?", "ERROR", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    textBox1.Text += Environment.NewLine + "Downloading...  " + e.FileName;
                    textBox1.Text += Environment.NewLine + "Downloaded";
                    File.Create(e.FileName);
                }
                else
                {
                    textBox1.Text = "";
                    for ( int i = 0; i < 10; i++)
                    {
                        textBox1.Text += "MISSING: " + e.FileName+ Environment.NewLine;
                    }
                }
            }
            catch (Exception ex)
            {
                textBox1.Text += Environment.NewLine+ex;
            }
           
        }


and, to call...
Call Script:
SendFile("doyouknowpython.py", Directory.GetCurrentDirectory());
Let me know how to solve this problem..?
I'm struggling exactly same problem.
 
Show us your code. You may be having the same problems, but your code is probably completely different from the OP's code... Unless you just copied and pasted without understanding it.

Also tell us what you have already tried as to try to resolve the problem. There's no point in going over ground that you've already covered.

Also by posting details like that will let us split off a fresh thread for you specifically. This thread has already been marked as resolved so chances of people having interest in it will go down dramatically.
 

Latest posts

Back
Top Bottom