Modes of Connections

<< Click to display table of contents >>

Modes of Connections

This topic explains how data (video, audio, files, commands, etc.) may be transferred between two applications via the network.

One application (which sends data) uses TRVCamSender component. Another application (which receives data) uses TRVCamReceiver component.

There are several modes of connections possible. The modes has the following differences: which side initiates a connection; TRVMediaServer is used or not.

Working in different modes of connections

Information how to establishing different modes of connection can be found in the topic about TRVCamSender.

Connection from Sender to Receiver or MediaServer (UDP, TCP or HTTP)

In this mode, the Sender does not make permanent connections to the Receiver (so channels and sessions are not established). The Sender sends new data when they become available. The Receiver (or the MediaServer) listens to the port and processes received data.

The Receiver uses the following events (with the parameters SessionKey = 0 и MediaTypes= []): OnConnecting, OnConnected, OnDisconnect, OnConnectError.

The Sender uses the following events (SessionKey = Sender.SessionKey, and MediaTypes contains the type of data to send): OnConnected, OnConnecting, OnDisconnect, OnConnectError.

In this mode, the receiver does not use he following events: OnOpenChannel, OnCloseChannel, OnSessionConnected, OnSessionDisconnected.

Connection from Receiver to Sender or MediaServer (TCP or HTTP)

The receiver establishes a permanent connection to the Sender (or the MediaServer). For each data type, a channel is created. All channels make up a session. When all channels are opened, a session is created. If at least one channel is closed, a session is terminated.

In this mode, all the Receiver's events are used: OnConnecting, OnConnected, OnDisconnect, OnConnectError, OnOpenChannel, OnCloseChannel, OnSessionConnected, OnSessionDisconnected. In all events, except for OnSessionConnected, OnSessionDisconnected, the parameter SessionKey=0.

The sequence of the Receiver's events when opening/closing a channel:

1.OnOpenChannel

2.OnConnecting

3.OnConnected/OnConnectError

4.OnDisconnect (if no OnConnectError)

5.OnCloseChannel

When all channels are opened, OnSessionConnected occurs.

If at least one of channels is closed, OnSessionDisconnected occurs.

hmtoggle_arrow1Example

Connections between clients

Option 1: A direct connection without a server

In the Option 1, there are two possible modes for transferring data from Client1 to Client2. The both modes requires that at least one side has a "white IP address" (available for another side)

1.a) Client1 sends data to Client2, when new data are available

In this mode Client2 must be visible for Client1, i.e. Client2 must have an IP address which Client1 can use to make a connection. Otherwise, this mode is not possible to use.

This mode is the fastest, because data are sent from Client1 to Client2 immediately when they become available, without delays.

In this mode, a connection session is not created, because there are no permanent connections between the clients, a connection is created only when data are being sent, and it is terminated when the transfer is finished.

connect_sender_to_receiver

2.b) Client2 connects to Client1 and requests new data

In this mode Client1 must be visible for Client2, i.e. Client1 must have an IP address which Client2 can use to make a connection. Otherwise, this mode is not possible to use.

In this mode, permanent channels for each data type are opened. Client2 requests new data from each channel periodically. This type of connection was organized to provide a maximal possible bandwidth (if it would have been organized as a single channel, video data may overfill the channel, slowing down transfer of data of other types).

connect_receiver_to_sender

Option 2: Client-Server-Client

In this mode, Client1 sends data to Client2 via the Server. In this mode, only the Server must have a "white IP address".

Client1 connects to the Server directly. It does not create permanent channels, so the Server does not need to request data from the Client. When new data become available, Client1 connects to the Server and transfers them.

A situation for Client2 is different. It creates permanent channels for each data type and requests data from the Server periodically. It makes it possible for Client2 to work without a white IP address. Multiple channels allow to transfer data efficiently, but increase the server load.

connect_server

This option of connection is used to organize transfers between multiple clients, creating groups of clients, contact lists, etc. A Server can help to to transfer data between clients that cannot connect to each other directly.