Windows to Symbian IRDA sockets connection: Salvation

Login to reply to this topic.
Mon, 2006-06-05 11:17
Joined: 2006-04-03
Forum posts: 14
I've spent so much time to understand how to implement that... These pieces of $h1t that you can find in MSDN and Symbian documentation don't reveal anything. And there's no working example both for Windows and Symbian Evil
Here's a working example of establishing the IRDA socket communication. Symbian part is a "socket server", Windows - client.

Symbian Part:
Code:
#include "CommonFramework.h"
#include <es_sock.h>
#include <ir_sock.h>


const TUint KBeamPortNumber=37;

// do the example
LOCAL_C void doExampleL()
{

RSocketServ ss;
TProtocolDesc pInfo;
TInt ret;

ss.Connect();

_LIT8(KTinyTP,"IrTinyTP");
TProtocolName ProtName;
ProtName.Copy(KTinyTP);
ret=ss.FindProtocol(ProtName,pInfo);
// IrTinyTP is the reliable transport layer of IRDA
if (ret!=KErrNone)
{
// Error - protocol not loaded: prob. wrong ESOCK.INI
// or another protocol holds serial port
}

RSocket listener;
listener.Open(ss,pInfo.iAddrFamily,pInfo.iSockType,pInfo.iProtocol);

TSockAddr a;
a.SetPort(KBeamPortNumber);
listener.Bind(a);
listener.Listen(1);

RSocket acceptor;
acceptor.Open(ss); // Create a null socket to hold the connection

TRequestStatus stat;

listener.Accept(acceptor,stat);
User::WaitForRequest(stat); // con now holds the connected socket

TBuf8<100> b;
b.FillZ();
acceptor.Read(b,stat); // Reading from accepted socket.
User::WaitForRequest(stat);

TBuf16<100> Msg;
Msg.Copy(b);
User::InfoPrint(Msg);

acceptor.Write(b,stat);
User::WaitForRequest(stat);

console->Getch();

acceptor.Close();
listener.Close();
ss.Close();
}

Windows part:
Code:
#include <stdio.h>
#include <winsock2.h>
#include <windows.h>
#include <af_irda.h>


const int KBeamPortNumber=37;

int main(int arc, char ** argv)
{
WSADATA    WSAData = {0};
WSAStartup(MAKEWORD(2, 2), &WSAData);

SOCKET Sock;

if ((Sock = socket(AF_IRDA, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
// WSAGetLastError
}

// search for the peer device


#define DEVICE_LIST_LEN    10
// discovery buffer
BYTE          DevListBuff[sizeof(DEVICELIST) - sizeof(IRDA_DEVICE_INFO) +
(sizeof(IRDA_DEVICE_INFO) * DEVICE_LIST_LEN)];
int           DevListLen = sizeof(DevListBuff);
PDEVICELIST   pDevList   = (PDEVICELIST) &DevListBuff;

pDevList->numDevice = 0;
if (getsockopt(Sock, SOL_IRLMP, IRLMP_ENUMDEVICES, (CHAR *) pDevList, &DevListLen)
== SOCKET_ERROR)
{
// WSAGetLastError
}

#define IAS_QUERY_ATTRIB_MAX_LEN 32

// buffer for IAS query
BYTE          IASQueryBuff[sizeof(IAS_QUERY) - 3 + IAS_QUERY_ATTRIB_MAX_LEN];
int           IASQueryLen = sizeof(IASQueryBuff);
PIAS_QUERY    pIASQuery   = (PIAS_QUERY) &IASQueryBuff;


if (getsockopt(Sock, SOL_IRLMP, IRLMP_IAS_QUERY,  (char *) pIASQuery, &IASQueryLen) == SOCKET_ERROR)
{
WSAGetLastError();
}


SOCKADDR_IRDA DstAddrIR = { AF_IRDA, 0, 0, 0, 0, {0} };
sprintf(DstAddrIR.irdaServiceName,"LSAP-SEL%d",KBeamPortNumber);

// assume first device, we should have a common dialog here
memcpy(&DstAddrIR.irdaDeviceID[0], &pDevList->Device[0].irdaDeviceID[0], 4);


// nothing special for IrCOMM from now on...
if (connect(Sock, (const struct sockaddr *) &DstAddrIR, sizeof(SOCKADDR_IRDA)) == SOCKET_ERROR)
{
WSAGetLastError();
}

char testreq[]="preved";
send(Sock,testreq,sizeof(testreq),0);
char Buffer[sizeof(testreq)]={0};
recv(Sock,Buffer,sizeof(Buffer),0);

shutdown(Sock,SD_BOTH);

WSACleanup();

return 0;
}

Usage:
1) run the server on the phone.
2) when the irda connection is established run the client

The client will send a test string "preved" Smiley The server will display it and will send it back to client.

Wed, 2007-03-07 01:03
Joined: 2007-03-06
Forum posts: 3
Re: Windows to Symbian IRDA sockets connection: Salvation
Anyone had joy getting this working in reverse, i.e. server on computer and client on phone?
  • Login to reply to this topic.