Wireless data transmission

Information encoded as variability of electromagnetic fields:

  • frequency (f): wave oscillation speed, ==higher f shorter range==
  • wavelength (): inverse of frequency, ==higher longer antenna==
  • bandwidth: width of a range of frequencies used, ==more bandwidth higher throughput==

Sender (Tx) includes oscillator DAC, receiver (Rx) includes oscillator ADC

Smartphone wireless interfaces

Wireless interface selection impact:

  • capabilities - transfer speed, coverage area and maximum range
  • monetary cost
  • power consumption
Near Field Communication (NFC)BluetoothWiFiCellular network
PowerLow / noLow (~10mW)Medium (~100mW)High (~200mW)
RangeShort (~10cm)Short (~10m)Medium (~100m)Long (~1km)
ThroughputLow (~400kbps)Low (~1Mbps)High (~100Mbps)Varying (~40kbps with 2G, ~1Gbps with 5G)
UsageSecurity tags, location-based services, payment systemsPeripherals and wearables, medical equipment, vehicle systemsLarge downloads, home entertainmentReal-time updates
Interface management: NfcManager, BluetoothManager, WifiManager, TelephonyManager, …
ConnectivityManager: network connections monitoring, connectivity changes notifications

Networking abstractions

Sockets

Socket - TCP, DatagramSocket - UDP

Http(s)URLConnection

HTTP(S) connection and transfers:

  • connection pooling socket reuse
  • response caching
  • cookie management

OkHttp (3rd party library)

Advanced HTTP client:

  • all features of HttpsURLConnection
  • automatic network connection recovery, retries
  • data compression

Retrofit (3rd party library)

REST client using (OkHttp under the hood):

  • define model and REST operations
  • define converter and adapter
  • define authentication mechanisms





Best practices

  • Run network operations on a separate thread
  • Reduce amount of data transfers:
    • compress data / use low resolution content when possible
    • query only what’s needed
    • cache static (and dynamic as much) content
  • Get notified on remote data change instead of polling
  • Reuse network connections
  • Secure connection (SSL) and minimize sensitive data transfers
  • Energy-efficient networking:
    • bundle data send data less frequently
    • use WorkManager
  • Adapt to available connection:
    • slower network reduce transfers
    • faster network prefetch

Backend for mobile apps

Firebase (Google-developed):

  • Authentication with Google ID
  • Notifications
  • Crashlytics

Parse server (open source backend as a service):

  • building REST APIs
  • cron jobs on server
  • user management