This example demonstrates the use of the RConnection
API to do connection monitoring and management.
The example demonstrates the following
features of the RConnection
API:
Opening and
closing a connection using RConnection::Open(RSocketServ&
aSocketServer, TUint aConnectionType = KConnectionTypeDefault)
and RConnection::Close()
.
Starting a connection
that uses the default CommDb connection preferences, and another connection
that overrides them, using (respectively) RConnection::Start()
and RConnection::Start(TConnPref& aPref)
.
Getting the
number of connections, and retrieving information about one of them,
using RConnection::EnumerateConnections(TUint&
aCount)
and RConnection::GetConnectionInfo(TUint
aIndex, TDes8& aConnectionInfo)
.
Attaching a
connection to an existing interface, using RConnection::Attach(const
TDesC8& aConnectionInfo, TConnAttachType aAttachType)
.
Registering for notifications when:
a certain amount
of data has been sent, using RConnection::DataSentNotificationRequest(TUint
aThreshold, TPckg<TUint>& aUplinkVolume,
TRequestStatus& aStatus)
.
a certain amout
of data has been received, using RConnection::DataReceivedNotificationRequest(TUint
aThreshold, TPckg<TUint>& aDownlinkVolume,
TRequestStatus& aStatus)
.
interfaces go
up and down, using RConnection::AllInterfaceNotification(TDes8&
aNotification, TRequestStatus& aStatus)
.
the connection
changes state, using RConnection::ProgressNotification(TNifProgressBuf&
aProgress, TRequestStatus& aStatus, TUint
aSelectedProgress = KConnProgressDefault)
.
Obtaining the
amount of data transferred, using RConnection::DataTransferredRequest()
.
Obtaining the
connection's current state, using RConnection::Progress(TNifProgress&
aProgress)
.
Stopping the
connection, using RConnection::Stop()
.
Closing the
session with the socket server using RSocketServ::Close()
.
Click on the following link to download the example: Rconnection.zip
Click: browse to view the example code.
The example demonstrates the following classes:
TCommDbConnPref
TConnectionInfoBuf
The project implements
a single class called CRConnection
, that has three
principal functions:
CRConnection::DemoApiWithoutDbOverrideL()
This shows how to use RConnection
to:
start a connection and associate it with an underlying interface, using default CommDb connection preferences,
get notification when the underlying interface goes up or down,
get notification about the state of a connection as it becomes fully established,
transfer data over a socket,
get the amount of data transferred,
close the connection.
It also shows how to set up a socket to carry out data transfer.
CRConnection::DemoApiWithDbOverrideL()
This is
the same as DemoApiWithoutDbOverrideL()
except that
it:
starts a connection using non-default CommDb connection preferences,
requests notification when a threshold amount of data has been transferred (instead of getting the amount of data transferred).
CRConnection::AttachToExistingInterfaceL()
This shows how to use RConnection
to:
You can build the example from the IDE or the command line.
If you use an
IDE, import the bld.inf
file into your IDE, and
use the build command of the IDE.
If you use the command line, open a command prompt, and set the current directory to the source code directory of the example. You can then build the example using the SBSv1 build tools with the following commands:
bldmake bldfiles
abld build
Emulator:
Before running the example, the emulator must be set up to use ethernet, as follows:
Install WinPCap 4.0.2
Configure the emulator using configchange.pl for instance:
configchange.pl --config ethernetWithCommDB --kernel EKA2 --target winscw --variant udeb
Open ethernetced.xml
in epoc32\winscw\c\
and change the last 3 values in the LANBearer operation
section for "EKA2 Emulator Ethernet" in the LANBearerTable
to:
LastSocketActivityTimeout = 10 LastSessionClosedTimeout = 10 LastSocketClosedTimeout = 10
i.e. change the three values from -1 to 10.
Save the file
and then run ced c:\ethernetced.xml
from the eshell
command prompt in the emulator.
Download a UDP Echoserver. An Echoserver is easily available on the internet.
Start the UDP
Echoserver and edit the rconnection.cpp
file in the
example code so that the values for KDestAddr
and KSockPort
match the values being used by the UDP Echoserver.
Build the application using the commands described above and then run it.
Hardware:
For the emulator, the
example builds an executable called rconnection.exe
in the epoc32\release\winscw\<udeb or urel>\
folder.
rconnection.exe
is a console-based
application. The example takes input from the user and prints to the
console information about the various stages of the example.