previous next

Chapter 14: Network Services

RealSystem's Network Services provides cross-platform methods for managing network communictions. Any server-side or client-side RealSystem component can use Network Services to create TCP or UDP connections for reading and writing data. Network Services also provides interfaces that let components resolve DNS host names and listen for TCP connections on specified ports.

Interfaces

A RealSystem component uses the following interface to access Network Services:

A RealSystem component implements the following asynchronous response interfaces to use Network Services:

Network Services also includes the following platform-specific interface:

Creating a Listen Socket

A RealSystem component does the following to set up a TCP listening socket and receive notice of a TCP connection on a local port:

  1. The component calls IRMANetworkServices::CreateListenSocket and receives a pointer to the new socket interface.

  2. The component calls IRMAListenSocket::Init on the socket interface to identify itself as the response interface. This method also passes the local IP address and port number on which to listen.

  3. When a TCP connection is made on the specified port, RealSystem creates an IRMATCPSocket interface and calls the component's IRMAListenResponse::NewConnection method, which returns a status code and a pointer to the TCP socket interface. The component can then use the TCP socket methods described below.

    Additional Information
    See "Status Codes".

Using a TCP Socket

A RealSystem component can create or inherit an existing TCP socket:

  1. If it needs to create the TCP socket interface, the component calls IRMANetworkServices::CreateTCPSocket and receives a pointer to the new socket interface. The component then calls IRMATCPSocket::Init to initialize the socket and identify itself as the response interface.

  2. If the component inherits an existing, initialized TCP socket, it uses IRMATCPSocket::SetResponse to identify itself as the response interface. It can also use the following IRMATCPSocket methods to return in local host order the addresses and ports of the TCP socket:

After it has set up the TCP socket, the component can perform the following actions:

Using a UDP Socket

To use a UDP socket, an object calls IRMANetworkServices::CreateUDPSocket and receives a pointer to the new socket interface. It then calls IRMAUDPSocket::Init to initialize the socket and identify itself as the response interface. This method also passes the IP connection address as a four-byte address in native byte order. (The component can use the resolver to get this address.) After it has set up the UDP socket, the component can perform the following actions with it (note that all addresses are in native byte order):

Resolving a DNS Host Name

A RealSystem component does the following to get the IP address for a DNS host name:

  1. The component calls IRMANetworkServices::CreateResolver and receives a pointer to the new resolver interface.

  2. The component calls IRMAResolver::Init to identify itself as the response interface.

  3. The component calls IRMAResolver::GetHostByName, passing RealSystem a DNS name in the form www.myserver.com. The system responds with IRMAResolverResponse::GetHostByNameDone, which returns a status code and a four-byte IP address in native byte order.

    Additional Information
    See "Status Codes".

Getting an I/O Callback on UNIX

On UNIX, RealSystem (RealServer or client) handles I/O events through the UNIX select() function. UNIX plug-ins do not have access to this function directly. If a plug-in needs to handle an I/O event, it sets up a callback through which RealSystem informs it that a specified file descriptor is ready for reading or writing, or has an exception:

  1. The plug-in implements IRMACallback.

  2. The plug-in calls IRMAAsyncIOSelection::Add, identifying itself as the callback interface and passing the system the file descriptor and type.

  3. When the file descriptor is ready for reading or writing, or has an exception, the system calls IRMACallback::Func.

  4. Within IRMACallback::Func, the plug-in handles the event as necessary.

  5. The plug-in can cancel a callback with IRMAAsyncIOSelection::Remove.


Copyright © 2000 RealNetworks
For technical support, please contact supportsdk@real.com.
This file last updated on 05/17/00 at 12:50:21.
previous next