Hi,
I tried that one too but failed. Here I am sending my server and client code. What I am trying is to create two ad hoc mode access points in two phones and then try to connect that two phones using a socket connection.
Following the server code:
Code:
CCommsDatabase* db = CCommsDatabase::NewL();
CleanupStack::PushL(db);
TInt err = db->BeginTransaction();
// Create a wlan AP and fill its mandatory fields.
CApAccessPointItem* wlanAp = CApAccessPointItem::NewLC();
CApAccessPointItem* wlanNewItem = CApAccessPointItem::NewLC();
wlanAp->SetNamesL(_L("MySSid"));
wlanAp->SetBearerTypeL(EApBearerTypeWLAN);
wlanAp->WriteTextL(EApWlanNetworkName, _L("MySSid")); // Give corrct Data as per the router configuration //L!nkSys@MdpNok!a
//Lan network mode should be 1 for infrastructure, 0 for adhoc
wlanAp->WriteUint(EApWlanNetworkMode,0);
wlanAp->WriteUint(EApWlanChannelId ,3);
// Setting up advanced settings for IP addressing
wlanAp->WriteTextL(EApWlanIpAddr ,_L("192.248.16.30"));
wlanAp->WriteTextL(EApWlanIpNetMask ,_L("255.255.255.00"));
wlanAp->WriteTextL(EApWlanIpGateway ,_L("192.248.16.30"));
TBool val =ETrue;
TUint32 newalanid;
CApDataHandler* handler = CApDataHandler::NewLC(*db);
TUint32 apid;
apid = handler->CreateFromDataL(*wlanAp);
handler->UpdateAccessPointDataL(*wlanAp,val);
handler->AccessPointDataL(apid,*wlanNewItem);
CApUtils *aputil = CApUtils::NewLC(*db);
TUint32 wapuid = wlanAp->WapUid();
TInt Iap = aputil->IapIdFromWapIdL(wapuid);
wlanNewItem->ReadUint( EApIapServiceId, newalanid );
TBuf<50> ibuff;
wlanNewItem->ReadTextL( EApWlanNetworkName, ibuff );
TUint32 newAPId = wlanNewItem->WapUid();
CCommsDbTableView* wLanServiceTable = db->OpenViewMatchingUintLC( TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), newalanid );
errorCode = wLanServiceTable->GotoFirstRecord();
if ( errorCode == KErrNone )
{
wLanServiceTable->UpdateRecord();
}
else
{
TUint32 dummyUid( 10 ); //KUidNone
User::LeaveIfError( wLanServiceTable->InsertRecord( dummyUid ) );
wLanServiceTable->WriteUintL( TPtrC( WLAN_SERVICE_ID ), apid );
}
wLanServiceTable->PutRecordChanges();
err = db->CommitTransaction();
CleanupStack::PopAndDestroy(5);
// Create an RConnection using a defined IAP
TInt error;
error = server.Connect(KESockDefaultMessageSlots);
error = connection.Open(server, KConnectionTypeDefault);
TCommDbConnPref prefs;
prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
prefs.SetDirection(ECommDbConnectionDirectionUnknown);
prefs.SetIapId(newAPId);
error = connection.Start(prefs);
// Creating the listenning socket
err = iListen.Open(server, KAfInet, KSockStream, KProtocolInetTcp, connection);
User::LeaveIfError(err);
// The second (blank) socket is required to build the connection & transfer data.
err = iSocket.Open(server);
User::LeaveIfError(err);
//Setting up the remote IP address
_LIT( KIPAddress, "192.248.16.30");
TInetAddr addr;
addr.Input( KIPAddress );
TUint32 aAddr;
aAddr = addr.Address();
// Binding the local infror to the listenner
TInt port = 1500;
/*TInetAddr anyAddrOnPort(aAddr, port);
iListen.Bind(anyAddrOnPort); */
iListen.SetLocalPort(port);
// Listen for incoming connections and accept an incoming connection.
iListen.Listen(5);
// On connection, subsequent data transfer will occur using the socket iSocket
iListen.Accept(iSocket, iStatus);
SetActive();
following is the client code
Code:
CCommsDatabase* db = CCommsDatabase::NewL();
CleanupStack::PushL(db);
TInt err = db->BeginTransaction();
// Create a wlan AP and fill its mandatory fields.
CApAccessPointItem* wlanAp = CApAccessPointItem::NewLC();
CApAccessPointItem* wlanNewItem=CApAccessPointItem::NewLC();
wlanAp->SetNamesL(_L("MySSid"));
wlanAp->SetBearerTypeL(EApBearerTypeWLAN);
wlanAp->WriteTextL(EApWlanNetworkName, _L("MySSid")); // Give corrct Data as per the router configuration //L!nkSys@MdpNok!a
//Lan network mode should be 1 for infrastructure, 0 for adhoc
wlanAp->WriteUint(EApWlanNetworkMode,0);
wlanAp->WriteUint(EApWlanChannelId ,3);
// Setting up advanced settings for IP addressing
wlanAp->WriteTextL(EApWlanIpAddr ,_L("192.248.16.31"));
wlanAp->WriteTextL(EApWlanIpNetMask ,_L("255.255.255.00"));
wlanAp->WriteTextL(EApWlanIpGateway ,_L("192.248.16.30"));
//wlanAp->WriteBool(EApIpv4Settings, ETrue);
TBool val =ETrue;
TUint32 newalanid;
CApDataHandler* handler = CApDataHandler::NewLC(*db);
TUint32 apid;
apid = handler->CreateFromDataL(*wlanAp);
handler->UpdateAccessPointDataL(*wlanAp,val);
handler->AccessPointDataL(apid,*wlanNewItem);
CApUtils *aputil = CApUtils::NewLC(*db);
TUint32 wapuid = wlanAp->WapUid();
TInt Iap = aputil->IapIdFromWapIdL(wapuid);
TUint32 newAPId = wlanNewItem->WapUid();
wlanNewItem->ReadUint( EApIapServiceId, newalanid );
TBuf<50> ibuff;
wlanNewItem->ReadTextL( EApWlanNetworkName, ibuff );
CCommsDbTableView* wLanServiceTable = db->OpenViewMatchingUintLC( TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), newalanid );
errorCode = wLanServiceTable->GotoFirstRecord();
if ( errorCode == KErrNone )
{
wLanServiceTable->UpdateRecord();
}
else
{
TUint32 dummyUid( 10 ); //KUidNone
User::LeaveIfError( wLanServiceTable->InsertRecord( dummyUid ) );
wLanServiceTable->WriteUintL( TPtrC( WLAN_SERVICE_ID ), apid );
}
wLanServiceTable->PutRecordChanges();
err = db->CommitTransaction();
CleanupStack::PopAndDestroy(5);
// Create an RConnection using a defined IAP
TInt error;
error = server.Connect(KESockDefaultMessageSlots);
error = connection.Open(server, KConnectionTypeDefault);
TCommDbConnPref prefs;
prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
prefs.SetDirection(ECommDbConnectionDirectionUnknown);
prefs.SetIapId(newAPId);
error = connection.Start(prefs);
// Creating the listenning socket
err = iListen.Open(server, KAfInet, KSockStream, KProtocolInetTcp, connection);
User::LeaveIfError(err);
//Setting up the remote IP address
_LIT( KIPAddress, "192.248.16.30");
TInetAddr addr;
addr.Input( KIPAddress );
TUint32 aAddr;
aAddr = addr.Address();
// Binding the local infror to the listenner
TInetAddr anyAddrOnPort(aAddr, 1500);
iListen.Connect(anyAddrOnPort, iStatus);
SetActive();
I have been trying this code for weeks. Can you all please sort it out for me ??
Regards,
Primal