Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to send an SMS using sockets

From Wiki
Jump to: navigation, search

This code will help to sending sms via a socket and you can send it via exe or an app also. Its very simple.

Article Metadata
Compatibility
Platform(s): Symbian (all)
Platform Security
Signing Required: Self-Signed
Capabilities: NetworkServices.
Article
Created: kkrish (14 May 2007)
Last edited: hamishwillee (13 Sep 2011)

Headers required:

#include <es_sock.h> //RSocketServ,RSocket
#include <smsuaddr.h> //TSmsAddr
#include <f32file.h> //RFs
#include <gsmuset.h> //TSmsUserDataSettings
#include <Gsmumsg.h> //CSmsMessage

Library Needed:

LIBRARY  esock.lib  //RSocketServ, RSocket
LIBRARY smsu.lib //TSmsAddr
LIBRARY efsrv.lib //RFs
LIBRARY gsmu.lib //TSmsUserDataSettings

Source:

RSocketServ sockServ;
User::LeaveIfError(sockServ.Connect());
CleanupClosePushL(sockServ);
 
RSocket socket;
User::LeaveIfError(
socket.Open(sockServ, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol));
CleanupClosePushL(socket);
 
TSmsAddr smsaddr;
smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly);
smsaddr.SetPort(smsaddr.Port() + 1);
 
User::LeaveIfError(socket.Bind(smsaddr));
 
RFs fileSession;
User::LeaveIfError(fileSession.Connect());
CleanupClosePushL(fileSession);
 
CSmsBufferBase *buffer = CSmsBuffer::NewL();
CleanupStack::PushL(buffer);
 
 
buffer->InsertL(0, _L("This is a test Message"));
 
TSmsUserDataSettings smsSettings;
smsSettings.SetAlphabet (TSmsDataCodingScheme::ESmsAlphabet8Bit);
smsSettings.SetTextCompressed(EFalse);
 
CSmsMessage *cSmsMessage = CSmsMessage::NewL(
fileSession, CSmsPDU::ESmsSubmit, buffer);
CleanupStack::Pop(buffer);
CleanupStack::PushL(cSmsMessage);
cSmsMessage->SetUserDataSettingsL(smsSettings);
cSmsMessage->SetToFromAddressL(_L("98888888888888"));
cSmsMessage->SmsPDU().SetServiceCenterAddressL(_L("+9999999"));
 
RSmsSocketWriteStream writestream(socket);
writestream << *cSmsMessage;
writestream.CommitL();
 
TRequestStatus status;
TPckgBuf<TUint> sendBuffer;
socket.Ioctl(KIoctlSendSmsMessage, status, &sendBuffer, KSolSmsProv);
User::WaitForRequest(status);
 
CleanupStack::PopAndDestroy(cSmsMessage);
CleanupStack::PopAndDestroy(&fileSession);
CleanupStack::PopAndDestroy(&socket);
CleanupStack::PopAndDestroy(&sockServ);

Related Links:

This page was last modified on 13 September 2011, at 01:26.
73 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×