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());