Chapter 4. Recipes

Table of Contents

Opening a connection
Setting connection parameters
Looking up and counting channels
Fetching offline data
Grabbing online or offline data progressively
Getting channel availability
This chapter explains the NDS client programming interface by example with recipes for common tasks.

Opening a connection

To open a new connection, create a new connection object with nds2.connection(). The arguments are the server's hostname, port number, and the protocol version. If the port number is omitted, then the default port is 31200. If the protocol version is omitted, then the protocol version is automatically detected by first attempting an NDS2 connection and then falling back to NDS1.

Example 4.1. Opening a connection in Python

Open a connection, discovering the server's protocol version automatically.
>>> conn = nds2.connection('example.edu')
Equivalent to:
>>> conn = nds2.connection('example.edu', 31200)
Equivalent to:
>>> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_TRY)
And also equivalent to:
>>> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_ONE | nds2.connection.PROTOCOL_TWO)

Open a connection to an NDS protocol 1 server.
>>> conn = nds2.connection('example.edu', 31200, 1)
Equivalent to:
>>> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_ONE)

Open a connection to an NDS protocol 2 server.
>>> conn = nds2.connection('example.edu', 31200, 2)
Equivalent to:
>>> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_TWO)

Example 4.2. Opening a connection in Octave

Open a connection, discovering the server's protocol version automatically.
octave:1> conn = nds2.connection('example.edu')
Equivalent to:
octave:1> conn = nds2.connection('example.edu', 31200)
Equivalent to:
octave:2> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_TRY)
And also equivalent to:
octave:3> conn = nds2.connection('example.edu', 31200, bitor(nds2.connection.PROTOCOL_ONE, nds2.connection.PROTOCOL_TWO))

Open a connection to an NDS protocol 1 server.
octave:4> conn = nds2.connection('example.edu', 31200, 1)
Equivalent to:
octave:5> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_ONE)

Open a connection to an NDS protocol 2 server.
octave:6> conn = nds2.connection('example.edu', 31200, 2)
Equivalent to:
octave:7> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_TWO)

Example 4.3. Opening a connection in MATLAB

Open a connection, discovering the server's protocol version automatically.
>> conn = nds2.connection('example.edu')
Equivalent to:
>> conn = nds2.connection('example.edu', 31200)
Equivalent to:
>> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_TRY)
And also equivalent to:
>> conn = nds2.connection('example.edu', 31200, bitor(nds2.connection.PROTOCOL_ONE, nds2.connection.PROTOCOL_TWO))

Open a connection to an NDS protocol 1 server.
>> conn = nds2.connection('example.edu', 31200, 1)
Equivalent to:
>> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_ONE)

Open a connection to an NDS protocol 2 server.
>> conn = nds2.connection('example.edu', 31200, 2)
Equivalent to:
>> conn = nds2.connection('example.edu', 31200, nds2.connection.PROTOCOL_TWO)