×
Namespaces

Variants
Actions

How to send an SMS using sockets

From Nokia Developer 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 04:26.
95 page views in the last 30 days.
×