elite12
July 22nd, 2003, 06:11 AM
hi
the following code gives me the error even i included winsock32.lib or ws2_32.lib.
The platform SDK clearly specifies IRDA support.
the WSAGetLastError() returns me 10047
stating "Address family not supported by protocol family. "
this is from MSDN :
SOCKET ServSock;
if ((ServSock = socket(AF_IRDA, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
printf("\n error in sockets : %d", WSAGetLastError());
return;
}
apart form this if any one give me a sample code on IRDA it will be helpful.
Many Thanks!!!
someone
July 22nd, 2003, 06:33 AM
Did you use WSAStartup before you code?
elite12
July 22nd, 2003, 06:45 AM
Yes I have done WSAStartup:
The error is :
WSAEAFNOSUPPORT
10047
Address family not supported by protocol family.
usmarine
July 25th, 2003, 04:40 AM
What version of winsock are you specifing in WSAStartup()? Are you including Af_irda.h? This file is needed for IRDA support. Are you using SOCKADDR_IRDA instead of SOCKADDR_IN? Your call to socket() is correct, the problem is somewhere else in your code!
elite12
July 25th, 2003, 05:50 AM
I have fixed the problem it was due to the fact that no irsocket is created untill atleast a reciever is connected to the PC.
Now it is giving connection refused error although it does discover my Nokia 6100 correctly. here is the code.
if ((sock = socket (AF_IRDA, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
wsprintf (szError, TEXT("Allocating socket failed. Error: %d"),
WSAGetLastError ());
MessageBox (NULL, szError, TEXT("Error"), MB_OK);
return FALSE;
}
// Initialize the number of devices to zero.
devList.numDevice = 0;
while ( (devList.numDevice == 0) && (iCount <= NUMRETYR))
{
// Retrieve the socket option.
if (getsockopt (sock, SOL_IRLMP, IRLMP_ENUMDEVICES,
(char *)&devList, &iDevListLen) == SOCKET_ERROR)
{
wsprintf (szError, TEXT("Server could not be located, getsockopt")
TEXT(" failed. Error: %d"), WSAGetLastError ());
MessageBox (NULL, szError, TEXT("Error"), MB_OK);
closesocket (sock);
return FALSE;
}
iCount++;
// Wait one second before retrying.
Sleep (1000);
}
if (iCount > NUMRETYR)
{
MessageBox (NULL, TEXT ("Server could not be located!"),
TEXT ("Error"), MB_OK);
closesocket (sock);
return FALSE;
}
// Get the server socket address.
for (index = 0; index <= 3; index++)
{
address.irdaDeviceID[index] = devList.Device[0].irdaDeviceID[index];
}
// Establish a connection to the socket.
if (connect (sock, (struct sockaddr *)&address,
sizeof (SOCKADDR_IRDA)) == SOCKET_ERROR)
{
wsprintf (szError,
TEXT("Connecting to the server failed. Error: %d, %s, "),
WSAGetLastError (),devList.Device[0].irdaDeviceID);
MessageBox (NULL, szError, TEXT("Error"), MB_OK);
closesocket (sock);
return FALSE;
}
usmarine
July 25th, 2003, 06:20 AM
do you ever bind or setsocketopt ?
elite12
July 25th, 2003, 06:28 AM
its a client programm and it is connecting with a Nokia 6100 mobile. Also msn specifies that connection refused error is also thrown when there is no server on the other side but I do not know if the mobile acts as a server or a client.
usmarine
July 25th, 2003, 06:29 AM
you have to be the server nokia is the client
elite12
July 25th, 2003, 06:39 AM
hmm.
Then what serverice do I connect to
“IrDA:TinyTP:LsapSel” or “IrDA:IrLMP:LsapSel”
or nay else to get the port from IAS from the server (mobile).