Discussion Board

Results 1 to 14 of 14
  1. #1
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Hi All,

    I am trying to connect two mobile phones through an ad hoc mode access point.

    Is it possible to connect two mobile phones directly through an ad hoc mode access point ?

    How can I assign an IP address to the phones ?
    So that I can directly open a socket connection to that IP ...

    Can anyone help me in this matter ...

    Regards,
    Primal

  2. #2
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    Check the very first reply in your original post http://discussion.forum.nokia.com/fo...d.php?t=125171 : I have answered your question in less than 3 hours. It happened exactly 3 weeks ago, but you have not tried it, instead failed with some other API. Your choice.

  3. #3
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Sorry for that Wizard_hu, I failed in creating an access point in ad hoc mode through the code and then had to ask for help.

    Now I was able to create two ad hoc mode access points in the two phones with the same Network name and access point name using the code. In the one phone I created socket listener with the IP address "KInetAddrAny" and the port "1500".

    In the other phone I tried to connect to an IP address "192.248.16.30" and the port "1500" through a socket connection connected to the created access point. But it was not successful. I could not pass any message.

    When I created the access point and connect to it with in the same phone, I could see that access point in the other phone as well. But still I could not open a socket connection to the other phone. What could be the reason ?

    Regards,
    Primal

  4. #4
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    On the server device you should RConnection::Start the Ad-hoc access point from code (and use the same RConnection object with RSocket::Open for Accept-or socket).

  5. #5
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Yes, I specifically created a connection to the newly created access point (using the access point ID ) through the code and I used that connection in starting the socket server and in turn to accept the socket. But it didn't work. Do I have to bind a specific IP for that ? What could be the reason for not accepting the client connection from the server side?

    Regards,
    Primal

  6. #6
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Hi All,

    Is there any possibility to assign an IP address to an ad hoc mode access point through the code ?

    Regards,
    Primal

  7. #7
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Hi,

    I created two ad hoc mode access points in two phones having the same SSID, Channel N0 and same Gateway and Subnet mask. Then I created a connection to those created APs in respective phones.

    Finally using that connection, in one phone I tried to listen to a port through a socket (socket.accept), having its IP address bind to it. In the other phone, I tried to connect to the other phone using its IP address through the socket.connect.

    But still the connection is not establishing between two phones. What could be the reason ?

    Please please help me !!!

    Regards,
    Primal

  8. #8
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    I am not sure, you may try a simple SetLocalPort on the server side instead of Bind.

  9. #9
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    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

  10. #10
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Hi All,

    Do i need to have capability "NetworkServices" to send and receive data using a socket connection ??

    Plz help me, I am stuck here for weeks.

    Regards,
    Primal

  11. #11
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    Quote Originally Posted by primal View Post
    Do i need to have capability "NetworkServices" to send and receive data using a socket connection ??
    Of course you need.
    Plz help me, I am stuck here for weeks.
    If you remove/comment/#ifdef the WLAN-related parts of your code, pure networking does work in the emulator and such requirements are quickly appear in epocwind.out.
    By the way, I am almost sure that you need capabilities to use CApUtils (or what the name of that API is), make sure that you have added them.
    Handling error-codes also reveals such problems: you get KErrPermissionDenied (-46 as I remember) when you are trying to do things without the necessary capabilities.

  12. #12
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Thanx Wizard_hu,

    Yes, I had to add the "WriteDeviceData" capability inorder to add a new ad hoc access point through the code. What I am asking is, do I need aditional capabilities as well for a socket connection over ad hoc wireless connection ?

    Anyway I will try your suggestion to know whether I need any additional capabilities ...

    Regards,
    pirmal

  13. #13
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    You can and should experiment of course, however I am sure that NetworkServices is mandatory for anything that uses an IAP (even implicitly with RSocket::Connect to a non-local address).

  14. #14
    Regular Contributor primal's Avatar
    Join Date
    Nov 2007
    Location
    Moratuwa, Sri Lanka
    Posts
    86
    Hey Thanx a lot wizard_hu,

    Its finally working. i think the main reason for not working earlier, is that I have not added the "NetworkService" capability. Thanx again for your help ....

    Regards,
    primal

Similar Threads

  1. Nokia 6101 Locked 2 TMobile Midlet can't access internet...
    By Jason Glass in forum Mobile Java Networking & Messaging & Security
    Replies: 45
    Last Post: 2007-11-14, 02:19
  2. http hang the app after selecting access point
    By anglina in forum Symbian C++
    Replies: 5
    Last Post: 2007-08-04, 17:56
  3. Choosing Access point for Http connection
    By kakgul in forum Mobile Java General
    Replies: 3
    Last Post: 2004-09-06, 11:56
  4. Nokia 6600 Bluetooth Connection with Red-M Access Point
    By latthaphon in forum Bluetooth Technology
    Replies: 1
    Last Post: 2003-12-26, 19:02
  5. configuration of access point for socket connection
    By chunzhu in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2003-11-10, 13:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved