Accessing TCP/IP Sockets Tutorial

This topic describes how to access TCP/IP sockets.

You must be familiar with RSocketServ() and RSocket() to understand this tutorial.

Client programs access TCP/IP sockets through the generic socket interface RSocket(). The RSocket() specifies the protocol-specific behaviour through argument values. This tutorial contains notes on the usage of RSocket() functions for TCP and UDP sockets.

The high level steps to access the TCP/IP sockets are as follows:

  1. The RSocket() function takes a number of parameters that determine the type of socket connection to provide. The following are the important parameters for TCP/IP or UDP:

    1. addrFamily

    2. sockType

    3. protocol

  2. The following constant values must be used for TCP/IP: addrFamily: KAfInet or KAfInet6 for IPv6 sockType: KSockStream for TCP/IP or KSockDatagram for UDP protocol: KProtocolInetTCP or KProtocolInetUDP

Example

The following code is an example to access the TCP/IP socket:


void Example::open(void)
{    
    TInt err;
    RSocketServ ss;
    RSocket sock;

    err = ss.Connect();
    err = sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp);
    // ... now connect to the socket to send and receive data

Related concepts