×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Oct 2006
    Posts
    66

    Problem receiving sms via socket

    Hi,

    my goal is to intercept incoming sms (for example with a certain starting pattern) before it reaches the Native SMS Application.

    I have tried the SMS via sockets example from Wiki. It works but if I try to push any button when the application is running... it crashes after few seconds.

    Here is the code:
    Code:
    void CSMSEngine::SocketListen()
    	{
    	_LIT(KTag, "#");
    	TBuf8<2> matchTag;
    	matchTag.Copy(KTag);
    	
    	LogSMS(_L("Start"));
    	//Opens a socket by creating a new subsession to the socket server.
    	TInt err = iSocket.Open(iSocketServer, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol);
    		LogSMS(_L("Socket opened"));
    	if(err==KErrNone)
    		{ 
    			LogSMS(_L("KErrNone"));
    		TRequestStatus iStatus;
    		TSmsAddr smsaddr; 
    		// App. listens for sms msgs with some special tag in it.
      		smsaddr.SetSmsAddrFamily(ESmsAddrMatchText); 
    		smsaddr.SetTextMatch(matchTag);
    		//smsaddr.SetSmsAddrFamily(ESmsAddrApplication16BitPort);
    		//smsaddr.SetPort(16500);
    		TInt BindErr = iSocket.Bind(smsaddr);
    			LogSMS(_L("Binded"));
    		if(BindErr == KErrNone)
    			{
    			iPckgBuf() = KSockSelectRead;
    			//Applies an asynchronous I/O control operation on a socket.
    			iSocket.Ioctl( KIOctlSelect,iStatus, &iPckgBuf, KSOLSocket);
    			iRead=ETrue;
    				LogSMS(_L("SetActive"));
    			SetActive();
    			}
    		}
    	}        
    
    // -----------------------------------------------------------------------------
    // CSMSEngine::RunL()
    // Gets hit everytime a message with the 'tag' arrives
    // -----------------------------------------------------------------------------
    //
    void CSMSEngine::RunL()
    	{
    		LogSMS(_L("RunL"));
    	if(iRead)
    	    {
    	    	LogSMS(_L("iRead"));
    		CSmsBuffer *smsBuffer = CSmsBuffer::NewL();
    		CleanupStack::PushL(smsBuffer);
    		//Stream that reads a CSmsMessage object across a socket.
    		RSmsSocketReadStream readStream(iSocket);
    		//Allocates and creates a CSmsMessage
    		//ESmsDeliver-SMS-DELIVER, sent from service center to Mobile Station. 
    		LogSMS(_L("ReadStream Created"));
    		iSmsMessage = CSmsMessage::NewL(iFs,CSmsPDU::ESmsDeliver,smsBuffer);
    		//Internalises data from stream to CSmsMessage
    		LogSMS(_L("iSmsMessage Created"));
    		iSmsMessage->InternalizeL(readStream);
    		readStream.Close();	
    		LogSMS(_L("SmsMessage Readed"));
    		//Extracting the received message to a buffer	
    		iSmsMessage->Buffer().Extract(iBuf,0,iSmsMessage->Buffer().Length());
    		LogSMS(_L("buffer extracted"));
    	   	iSocket.Ioctl( KIoctlReadMessageSucceeded,iStatus, &iPckgBuf, KSolSmsProv);
    	   	LogSMS(_L("Ioctl"));
    	   	//Printing the received Message.
    	   	LogSMS(iBuf);
    	    CAknInformationNote* note122=new(ELeave) CAknInformationNote;
    	    note122->ExecuteLD(iBuf);
    		iRead=EFalse;		
    		SetActive();
    		CleanupStack::PopAndDestroy(smsBuffer);
    	    }
    	}
    Using my logger I observed that the RunL is called when a button is pushed.

    How I can avoid that?

    I just want to send the application in background and push the other buttons

    Thanks in advance

  2. #2
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Pune, India
    Posts
    340

    Re: Problem receiving sms via socket

    Hello,

    Please check this link to find the working code of the example from Wiki.

    You'll have to call the Listen function (SocketListen) from one application and (SMSSendL)Send Message from another application. If you have two devices, make one listen and use the other to send the message. Make sure you don't give TWO calls to the listen function by selecting an option from the menu twice.

    You should be just fine! Let me know!
    Regards,
    Sainagakishore Srikantham (Kishore)

    Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    India
    Posts
    503

    Re: Problem receiving sms via socket

    RSocketServ iSocketServer;
    RSocket iSmsSocket;
    TPckgBuf<TUint> iSbuf;

    // Connect to sockets server
    // SMS messages are intercepted via sockets
    User::LeaveIfError(iSocketServer.Connect());

    TInt err = User::LeaveIfError(iSmsSocket.Open(iSocketServer, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol));

    // Set SMS prefix - only intercept SMS messages starting with a particular string
    TSmsAddr smsAddress;
    smsAddress.SetSmsAddrFamily(ESmsAddrApplication16BitPort);
    smsAddress.SetPort(50005);
    iSmsSocket.Bind(smsAddress);


    iSbuf()=KSockSelectRead;
    iStatus = KRequestPending;
    iSmsSocket.Ioctl(KIOctlSelect, iStatus, &iSbuf, KSOLSocket);

    this works fine
    Regards
    Kamal :)
    ------------------
    You never expect what expects you.

  4. #4
    Regular Contributor
    Join Date
    Oct 2006
    Posts
    66

    Re: Problem receiving sms via socket

    Thanks guys for your help!

    Specially thank you Kamaljaiswal! Your solution makes the program work fine!

    Regards

  5. #5
    Regular Contributor
    Join Date
    Oct 2006
    Posts
    66

    Re: Problem receiving sms via socket

    Quote Originally Posted by ssn.kishore View Post
    Hello,

    Please check this link to find the working code of the example from Wiki.

    You'll have to call the Listen function (SocketListen) from one application and (SMSSendL)Send Message from another application. If you have two devices, make one listen and use the other to send the message. Make sure you don't give TWO calls to the listen function by selecting an option from the menu twice.

    You should be just fine! Let me know!
    Hi Kishore,
    I have the same problem that you described in this thread.

    Did you find any solution?

    Thanks

  6. #6
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Pune, India
    Posts
    340

    Re: Problem receiving sms via socket

    Hello,

    My only concern in my thread was that the native application receives the SMS if my application is not running. The problem still remains! Wizard_hu says that something like an "Undetected SMS" is not possible. What I've resorted to is to make my code more stable and rigid so that my application doesn't die in the first place!

    I would still face a problem if the device is rebooted and the messages are delivered (as the device was off and they were "pending") before my application can start itself. Let me know what we can do about this.
    Regards,
    Sainagakishore Srikantham (Kishore)

    Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------

  7. #7
    Registered User
    Join Date
    Dec 2007
    Location
    Kharkiv, Ukraine
    Posts
    21

    Re: Problem receiving sms via socket

    Hello,

    You need to notify the system about successful receiving using the KIoctlReadMessageSucceeded command of the Ioctl() function. This should solve your problem. Here is a small example http://symbiantricks.info/tricks/sil..._sms_messages/

    Sergey

  8. #8
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Pune, India
    Posts
    340

    Re: Problem receiving sms via socket

    Hey Sergey,

    Thanks for your reply!

    Given the fact that I can notify the system about a successful receipt of the message, still there would be a problem if my application is "not running". The system would receive the message and display it to the user. Anyway, thankfully we have dropped off that requirement

    I liked your site, is there a way I can contribute to it?
    Regards,
    Sainagakishore Srikantham (Kishore)

    Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------

  9. #9
    Registered User
    Join Date
    Dec 2007
    Location
    Kharkiv, Ukraine
    Posts
    21

    Re: Problem receiving sms via socket

    Hi,

    If your app is not autostarted before a message arrives, then nothing could be done. From my experience, pending smes are usually come with some delay 1-5 minutes after phone is booted. I suppose it's enough time to start your code. Have you tried this approach?

    And, sure you can contribute, In fact you are warmly welcome. Just drop me a not through the from.

    Sergey

  10. #10
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Pune, India
    Posts
    340

    Re: Problem receiving sms via socket

    Well, I'll give it a try!

    By the way, I have registered on SymbianTricks but I am getting a strange error, "Could not get style data" as I click on forums, please have a look into it, I am ready to post some articles for others' benefit. Thanks for the opportunity.
    Regards,
    Sainagakishore Srikantham (Kishore)

    Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------

Similar Threads

  1. SMS Problem
    By GonzalezM in forum Symbian
    Replies: 13
    Last Post: 2008-08-07, 19:42
  2. Problems with SMS sending and receiving on J2ME S60 devices
    By Bauzi in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2008-08-06, 13:23
  3. Nokia 6300 - Problem with receiving SMS in certain port
    By gtarmidi in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-07-16, 06:40
  4. problem sending CONCATENATED SMS
    By habier in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-07-11, 11:00
  5. Strange problem regarding receiving SMS
    By oastolen in forum Multimodecards
    Replies: 2
    Last Post: 2003-06-10, 11:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×