Rconnection: connection monitoring and management example

This example demonstrates the use of the RConnection API to do connection monitoring and management.

Purpose

The example demonstrates the following features of the RConnection API:

Download

Click on the following link to download the example: Rconnection.zip

Click: browse to view the example code.

Class Summary

The example demonstrates the following classes:

RConnection

RSocket

RSocketServ

TCommDbConnPref

TConnectionInfoBuf

Design and implementation

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:

  • open 2 connections and start one of them (the other is not yet associated with an underlying interface),

  • get connection information for the 1st connection and use this to attach the 2nd connection to the existing interface,

  • get the state of the attached connection,

  • close the connections.

Building and configuring

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

How to use bldmake and How to use abld describe how to use the SBSv1 build tools.

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:

  • To run the example on an H4 board, connect the H4 to the PC/network by serial cable. Copy ethernetced.xml to a memory card and execute:

    ced e:\ethernetced.xml

    before running the example.

Running the example

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.