×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Registered User
    Join Date
    Sep 2003
    Location
    Warsaw, Poland
    Posts
    16

    [Moved] Receiving SMS messages via sockets

    Hi,
    I'm trying to write an app which would seamlessly (i.e. without user interaction) intercept incoming SMSs, and reply to them.
    I basically follow the outlines from the "Symbian OS C++ for Mobile Phones" book, especially chapters on AOs and their SMS implementation of GDP.
    First, I struggled a lot to get the sending functionality in place, getting -5 (that is, KErrNotSupported) runtime errors on RSocket.Ioctl execution. Somehow, I finally managed to work that out, but now I'm stuck with receiving SMSs.
    For now, I just want to have a regular GUI app which waits for incoming SMSs. What I do is

    void MyClass::ReceiveSmsL()
    {
    RSocketServ iSocketServ;
    RSocket iSocket;
    CSMSReceiver* receiver;
    User::LeaveIfError(iSocketServ.Connect());
    iSocket.Open(iSocketServ, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol);
    TSmsAddr smsAddr;
    smsAddr.SetSmsAddrFamily(ESmsAddrRecvAny);
    iSocket.Bind(smsAddr);

    receiver = CSMSReceiver::NewL();
    TPckgBuf<TUint> ioctlResult = KSockSelectRead;
    iSocket.Ioctl(KIOctlSelect,receiver->iStatus ,&ioctlResult, KSOLSocket);
    }
    and CSMSReceiver only shows an info window in its RunL() method (I never got to see this window, though..)
    .When I send an SMS it goes to the phone's inbox, rather than being caught by my app, like I wanted it to work.
    CSMSReceiver, which derives after CActive, is for sure set to active and registered with the scheduler.
    Where is the problem?
    Thanks in advance for any help on this,
    Pawel

  2. #2
    Registered User
    Join Date
    Sep 2003
    Location
    Warsaw, Poland
    Posts
    16
    Hi again, on
    http://blader.amway-germany.de/hoste...rie=show&ID=35
    I found source code for getting info on incoming SMSs via MTM connection. Still, MTM doesn't allow for intercepting these messages, it's only a notification of a message that goes into the inbox anyway..

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    55
    Pawel,

    How did you manage to solve the KErrNotSupported error?

    I am having the exact same problem, however I am unable to solve this problem.

    Any help would be most appreciated.

    Steve

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    15

    Suggestion for Pawel

    Hi Pawel,

    I guess the reason why ur application is not able to receive the sms is that ur binding with the address (ESmsAddrRecvAny).The native messaging app of the phone has already a socket bound to the same address i.e ESmsAddrRecvAny.
    I am surprised how come ur not getting an error code when u execute :- socket.Bind(ESmsAddrRecvAny). It should return an error code as "AlreadyInUse" or similar.

    I suppose if u try binding with any other address(example ESmsAddrMatchText), ur application may start receiving SMS.

    U can give it a shot..it worked for me.
    Hope it helps.
    Sher

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    39
    hi sherissher! have you manage to listen for incoming sms on a socket? please help me i also need to do the same.. a snippet would be a great help!

    TIA

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    15

    Receiving SMS using Sockets.

    Hi Korn,

    The process is the same as described by Pawel.
    Anyways i will re-iterate .

    You make a class CActiveSocket which is derived from CActive.
    In this class, create a method SocketListen() in which u will open a socket, bind it to an address and start listening fr incomin messages.
    Another method RunL() will have to be implemented which will get hit everytime a request on the socket is completed.So everytime ur code receives a message this RunL() method will get hit and in this method u can read the data from the socket and do watever u want with it :-) i.e. display it to the user or save it in a file etc.

    The same process i would describe using the code reference below, but in case it is still not clear, let me know and i can send u my sample app.
    Note - make sure u have all the libraries used for sms in gsm or cdma, watever ur using.
    ---------------------------------------------------------------------------------
    CActiveSocket.h
    ---------------------------------------------------------------------------------
    CActiveSocket : public CActive
    {
    CActiveSocket();
    virtual ~CActiveSocket()();

    private: // from CActive
    void RunL();
    void DoCancel();

    };

    ---------------------------------------------------------------------------------------
    CActiveSocket.cpp
    --------------------------------------------------------------------------------------
    //Constructor
    CActiveSocket :: CActiveSocket()
    {
    CActiveScheduler::Add( this );
    }

    // here u open a socket, bind it an address and start listening .
    void CActiveSocket ::SocketListen()
    {
    _LIT(KTag, "@#");
    TBuf<2> matchTag;
    matchTag.Copy(KTag)

    TheFs.Connect();
    iSocketServer.Connect();

    TInt err = socket.Open(iSocketServer, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol);
    if(err==KErrNone)
    {

    TSmsAddr smsaddr;
    // here u specify that notify of all incomin messages with a particular tag
    // ur app must be listening for specific sms msgs with some special tag in it.
    // if u want to listen for all the incoming msgs u can use ESmsAddrRecvAny instead of ESmsAddrMatchText.
    // but i am not sure if that will work.
    smsaddr.SetSmsAddrFamily(ESmsAddrMatchText);
    smsaddr.SetTextMatch(matchTag);

    TInt BindErr = socket.Bind(smsaddr);
    if(BindErr == KErrNone)
    {

    sbuf() = KSockSelectRead;

    socket.Ioctl( KIOctlSelect, active->iStatus, &sbuf, KSOLSocket);
    active->ActiveSet();


    }
    }

    }

    // RunL() gets hit everytime a message with the 'tag' arrives
    void CActiveSocket::RunL()
    {
    _LIT(KTag, "@#");
    TBuf<2> matchTag;
    matchTag.Copy(KTag)

    CSmsMessage* message = CSmsMessage::NewL(TheFs, CSmsPDU::ESmsDeliver, CSmsBuffer::NewL());
    CleanupStack::PushL(message);

    RSmsSocketReadStream readStream(socket);
    CleanupClosePushL(readStream);
    message->InternalizeL(readStream);

    TBuf<255> buf;
    message->Buffer().Extract(buf,0,message->Buffer().Length());

    if( (buf.Left(2)).Compare(matchTag) == 0)
    {
    // here u have received the message with a particular tag in it.
    //Respond that message read successfully
    socket.Ioctl( KIoctlReadMessageSucceeded, active->iStatus, &sbuf, KSolSmsProv);

    }

    CleanupStack::PopAndDestroy(&readStream);
    CleanupStack::PopAndDestroy(message);

    }

    Note :- The code above is not perfect and mite not compile.Just tinker around with it and lemme know if u still face any problem.

    Hope it helps,
    Sher

  7. #7
    Registered User
    Join Date
    May 2004
    Posts
    39
    thanks sherissher.. i will try this code and hope you'll be there to help! =)

    anyways i noticed that you are using tags in identifying the sms.. is it possible to identify the sms by their respective sender's number? how can i retrieve the number? what possible api can i use?

    Thanks!

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    39
    hi again! since you have already suggested it.. sending me a sample app would be much of help! =)

    TIA

  9. #9
    Registered User
    Join Date
    May 2004
    Posts
    39
    hi again! =)

    you can send the sample app at kornhed(at)lycos.co.uk..
    im having trouble with the headers! =) please notify me as soon as possible..

    TIA

  10. #10
    Registered User
    Join Date
    May 2004
    Posts
    39
    hi again!

    please send the sample app! =)

    TIA

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    28
    Hi guys,

    Great info, btw take a look at the gdpsms example in the book "Symbian OS C++ for mobile phones".Its simple to port it to Series60 v2.00.

    BUT:

    How can I test an incoming sms message in the emulator?
    In V1.2 there is a fetcher called SMSInbox.

    BR,
    S

  12. #12
    Registered User
    Join Date
    Jul 2005
    Posts
    10

    Re: Receiving SMS messages via sockets

    hi all,

    did you test this method (sockets KSMSAddrFamily) on symbian 9.1? did it work?

    Thanks in advance.

  13. #13
    Registered User
    Join Date
    May 2003
    Location
    London (United Kingdom)
    Posts
    15

    Re: Receiving SMS messages via sockets

    Quote Originally Posted by habier
    l,
    did you test this method (sockets KSMSAddrFamily) on symbian 9.1? did it work?
    .
    Yes habier, I have tested it on E61 and SE M600i, it works fine apart from a problem having on all symbian platforms (if I receive two/more messages at same time it just picks the last one)

  14. #14
    Registered User
    Join Date
    May 2003
    Location
    London (United Kingdom)
    Posts
    15

    Re: Receiving SMS using Sockets.

    Hi sherissher

    I have implemented my solution in your way and it works fine apart from a some problem.

    I'm filtering SMS on text macth, and problem is that when I receive more then one messages at same time socket only notify the last one and does not pick rest of the messages, but it doesn't seem either that remaining messages are being consumed as when I reboot my phone they end up in Inbox.

    Please suggest If I'm missing something.

    Thanks in advance

  15. #15
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    Re: Receiving SMS messages via sockets

    We've implemented this on a E61 and it works well, except for one problem. Has anyone got this solution to work with wildcard characters in the SetTextMatch parameter? We've tried '@#*' and '@#?' to try intercept an SMS with '@#1' OR '@#2' but have had no luck.

    Has anyone been able to intercept SMS's using multiple SetTextMatch() parameters or wildcard characters in the SetTextMatch parameter on 9.x?

    Thanks in advanced.

    Jay

Similar Threads

  1. Receiving SMS messages
    By Freestyler in forum Mobile Java General
    Replies: 4
    Last Post: 2009-01-26, 04:16
  2. [Moved] Receiving Messages with S40.
    By ramey in forum General Development Questions
    Replies: 2
    Last Post: 2008-02-24, 14:27
  3. Receiving SMS messages via sockets
    By pawel_z in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2003-10-06, 15:49
  4. Receiving SMS messages
    By Freestyler in forum Mobile Java General
    Replies: 3
    Last Post: 2003-05-22, 17:06
  5. Receiving SMS messages
    By Freestyler in forum General Messaging
    Replies: 0
    Last Post: 2003-05-21, 12:32

Posting Permissions

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