473,659 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Winsock problem (Bluetooth)

I'm trying to implement a Bluetooth client application. But I get an error
when I try to "bind" the socket created with "socket" function. Here is the
code I'm using:

public class BTClient
{
internal const int WSADescriptionL ength = 256;
internal const int WSASysStatusLen = 128;
internal const int WSAVersionReque sted = 0x201;
internal const int AfBth = 32;
internal const int SockStream = 1;
internal const int BthProtoRFComm = 0x0003;
internal const int SolSocket = 0xffff;
internal const uint BtPortAny = unchecked((uint )-1);
internal const int NsBth = 16;

[StructLayout(La youtKind.Sequen tial)]
internal struct WSAData
{
internal short wVersion;
internal short wHighVersion;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = WSADescriptionL ength
+ 1)]
internal string szDescription;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = WSASysStatusLen +
1)]
internal string szSystemStatus;
internal int iMaxSockets;
internal int iMaxUdpDg;
internal IntPtr lpVenderInfo;
}

[StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Unicode)]
internal struct SockAddrBth
{
internal ushort addressFamily;
internal ulong btAddr;
internal Guid serviceClassId;
internal uint port;
}

[DllImport("ws2_ 32.dll", SetLastError=tr ue)]
private static extern int WSAGetLastError ();

[DllImport("ws2_ 32.dll", SetLastError=tr ue)]
private static extern int WSAStartup(int vVersionRequest ed, ref WSAData
lpWSAData);

[DllImport("ws2_ 32.dll", SetLastError=tr ue)]
private static extern int WSACleanup();

[DllImport("ws2_ 32.dll", SetLastError=tr ue)]
private static extern UIntPtr socket(int af, int type, int protocol);

[DllImport("ws2_ 32.dll", SetLastError=tr ue)]
private static extern int bind(UIntPtr s,ref SockAddrBth name, int
namelen);

public void CreateSocket()
{
int err = 0; //Error code

//Initialize Winsock
WSAData x = new WSAData();
WSAStartup(WSAV ersionRequested , ref x); //Works fine

//Open a socket
UIntPtr sock = socket(AfBth, SockStream, BthProtoRFComm) ; //Works
fine. sock == 3680
err = WSAGetLastError ();

//bind the socket
SockAddrBth sab = new SockAddrBth();
sab.addressFami ly = AfBth; //Should be AF_BTH == 32
sab.btAddr = 0; //Should be Zero
sab.serviceClas sId = new Guid(0x00000000 , 0x0000, 0x0000, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); //NULL_GUID
sab.port = 0; //number of service
channel, 0 or BT_PORT_ANY. 0 for client applications

int siz = Marshal.SizeOf( sab); //siz == 40
int z = bind(sock,ref sab, siz); //Returns -1
err = WSAGetLastError (); //Returns 10049 == "The specified
address is not a valid address for this computer."

//Cleanup
.....
}
}

I am unable to understand where I'm going wrong. Please help!

TIA

B Vidyadhar Joshi
Nov 16 '05 #1
0 3383

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2273
by: Thomas_Germany | last post by:
I would like to develop a smart device bluetooth application for pocket PC 2003. As I know, Pocket PC 2003 includes the microsoft bluetooth stack. My intention is to use the SDK from mircrosoft and not the expensive SDK from WIDCOMM to use the bluetooth programming interfaces. But, as I know most pocket PCs with integrated bluetooth chips use the WIDCOMM bluetooth stack. So my questions are as follows: 1) Is it possible to...
3
8041
by: Tor Erik Sønvisen | last post by:
Hi I'm making a server-side solution in Python and need to be able to communicate through bluetooth. Is there any bluetooth-packages out there for python? regards tores
0
1640
by: Mulham | last post by:
hi everybody... im a c# developer , but im very new in bluetooth programming ! my questions are : 1. i searched on msnd and found many c# functions for bluetooth, but i dont know wiether these functions work on any bluetooth dungle (sender/reciever) ? are there any restrictions on the dungle i use ? the only thing i have is the driver that came with the bluetooth USB dungle, wich is a product of "TRENDnet" (TBW-101UB Bluetooth).
1
5783
by: cmartin64x | last post by:
Hi, I am trying to make this simple code work but I have no success doing so: BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { sizeof(btsp) }; BLUETOOTH_DEVICE_INFO btdi = { sizeof(btdi) }; btsp.fReturnAuthenticated = TRUE; btsp.fReturnRemembered = TRUE;
4
2231
by: Boki | last post by:
Hi All, I am going to use some Bluetotoh API, should I include some special DLL or just call it directly? Best regards, Boki.
2
5427
by: colin | last post by:
Hi, Im having a tiresome amount of trouble with using a bluetooth serial link. The receiving end is a bluetooth-rs232 module conected to my embeded system. The PC has a little usb bluetooth dongle, ive tried a another dongle with widicom software as I was having problems with the IVT bluesoleil software. that seems to have got rid of some other problems,
6
8502
by: jabslim | last post by:
excuse me, im a newbie programmer and i need a code on how to to be able to send files from a mobile phone to a pc through bluetooth in vb.net can anyone post a code here on how to detect a bluetooth device and how to send files to the pc in vb.net? i would really really appreciate your help!!
1
2428
by: gringgos | last post by:
hi, friends... Currently i am doing a project based on bluetooth and Visual Basic 6.0. But i am unable to find any solution regarding bluetooth. But my supervisor gave her idea about do a code where it runs the bluetooth application as a hidden program to send the audio file. It is where when i click the button send, it will operate the file transfer wizard in the bluetooth application and when i click the bluetooth button it should operate...
1
6083
by: Z.K. | last post by:
I know this is probably not the correct newsgroup, but I can't find anywhere else that is appropriate to post it in. I need to figure out how to write a bluetooth program to access a bluetooth barcode scanner. After a lot of searching the Internet, I have come to the conclusion that something using RFCOMM would be best. Unfortunately, Bluetooth programming books are not exactly plentiful and finding a book on RFCOMM is almost...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.