Connecting and Disconnecting a Remote Host Tutorial

This topic describes how to connect and disconnect a remote host.

Introduction

To send and receive the data packets, a connection must be established with a remote host. This tutorial describes the following:

How to Connect to a Remote Host

The high level steps to connect to a remote host are as follows:

  1. The RSocket::Connect() function connects to a remote host. The RSocket::Connect() parameters identifies the required type of socket connection. For more information, see important parameters .

    For TCP sockets

    1. An active connection is made to the remote host. When the socket call completes successfully, the socket can send and receive data. To create a connection, the protocol must establish a network interface and a route to the destination. For more information about this process and return values, see the RSocket::Connect() function.

  2. For UDP

    1. UDP is a connectionless protocol which means the RSocket::Connect() does not have to be called before writing data with RSocket::SendTo(). It can be used to set the address for all data sent from the socket. In this case, Send()/Write() function can be used in addition to SendTo() function.

How to Disconnect from a Remote Host

For cancelling the connection

The RSocket::CancelConnect() function cancels the outstanding connect operation with a remote host. This function also cancels any outstanding RSocket::Ioctl() calls. After this call, a socket can be reconnected by RSocket::Connect() function.

How to Listen to a Connect Request

A TCP socket can be set to listen with RSocket::Listen(). The aDataOut argument is ignored.

How to Accept a Connect Request

A connection request to a listening socket can be accepted with RSocket::Accept(). An aConnectData argument cannot be specified.

How to Shut down a Connection

Use RSocket::Shutdown() to asynchronously shut down a TCP. Disconnection data is not supported.

The following table describes the effects of different types of shut down for TCP:

Type Action
ENormal Blocked reads and writes are terminated. No further data is accepted from the remote source and TCP disconnect is initiated.
EStopInput Blocked reads are terminated. No further data is accepted from the remote source.
EStopOutput Blocked writes are terminated. TCP disconnect is initiated.
Eimmediate Blocked reads and writes are terminated. The connection is terminated by sending a reset.