# xuningjack/androidnet architecture

> Architecture diagram of the GitHub repository xuningjack/androidnet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xuningjack/androidnet
- Repository: https://github.com/xuningjack/androidnet

## Overview

1. **Repo shape**
   - This is a **multi-module Android/Java networking demo suite**. Each top-level folder is mostly self-contained: `JavaSocketDemo`, `AndroidHttpDemo`, `WebViewDemo`, `Volley`, `VolleyDemo`, and `OkHttpDemo`.
   - The root Gradle files tie these pieces together, but the architecture is primarily a set of **independent demo applications/libraries**, not one monolith.

2. **JavaSocketDemo: plain Java network primitives**
   - This module demonstrates **core Java networking** outside Android UI concerns.
   - It contains small demos for **`InetAddress`**, **`URL`**, and reading URLs, plus socket examples for **single-client TCP**, **multi-client TCP**, and **UDP**.
   - The main data flow is direct client/server communication: console-style client code connects to server code, and UDP uses datagram send/receive instead of a persistent connection.

3. **AndroidHttpDemo: Android-side HTTP request basics**
   - This is a lightweight Android app focused on **legacy HTTP APIs**: `HttpClient` and `HttpURLConnection`.
   - The UI is centered on `MainActivity` and a single layout, with network calls likely triggered from the activity and results rendered back into the app.
   - The key boundary is **UI layer → HTTP API → remote server → response shown in the activity**.

4. **WebViewDemo: native/HTML/JavaScript bridge**
   - This app demonstrates **WebView integration**, including **JavaScript-to-Java interaction** and loading local HTML assets.
   - Assets such as `showjs.html` and `error.html` indicate that some web content is bundled locally rather than fetched remotely.
   - The architectural boundary here is between the **Android activity layer** and the **embedded browser runtime** inside `WebView`, with bidirectional JS/native communication.

5. **Vendored Volley library**
   - The `Volley` module contains the actual **Volley networking framework source**, including request queueing, cache/network dispatchers, response delivery, and toolbox utilities.
   - Important internal subsystems are:
     - **RequestQueue / dispatchers** for asynchronous scheduling
     - **Cache and network layers** for fetch/reuse behavior
     - **Toolbox requests** for strings, JSON, images, and HTTP stacks
   - This module is a reusable infrastructure layer consumed by `VolleyDemo`.

6. **VolleyDemo: app-level wrapper around Volley**
   - `VolleyDemo` is the example app built on top of the vendored Volley code.
   - It adds a small app-specific abstraction layer: `CustomVolleyRequest`, `VolleyListener`, `BitmapCache`, and `MyApplication`.
   - The data flow is **Activity → custom request wrapper → Volley RequestQueue → network/cache → callback listener → UI update**, with image support handled through cache-related classes.

7. **OkHttpDemo: custom OkHttp wrapper layer**
   - This app demonstrates **OkHttp usage plus a custom request/response abstraction**.
   - The app-specific package `com.jack.okhttp` contains reusable infrastructure:
     - `CommonOkHttpClient` for executing requests
     - `CommonRequest` and `RequestParams` for request construction
     - response/listener handlers for JSON, files, progress, and errors
   - It also includes a bundled **Gson JAR**, which matters because JSON responses are parsed into typed objects.

8. **OkHttpDemo domain layer**
   - The package `com.example.jack.okhttpdemo` contains the app-facing classes such as `MainActivity`, `Result`, `DnsBean`, `BaiduWeight`, and `Constants`.
   - This indicates a split between **transport/framework code** and **demo/domain/UI code**.
   - The main flow is **activity triggers a request → wrapper sends HTTP call → parsed result is returned through listener/handler → activity updates text or UI state**.

9. **Shared architectural pattern across the demos**
   - Most modules follow the same pattern: **presentation/activity layer**, **networking abstraction**, **response callback/handler**, and **UI update**.
   - The difference is the transport technology being showcased:
     - raw sockets in `JavaSocketDemo`
     - Android HTTP APIs in `AndroidHttpDemo`
     - WebView bridge in `WebViewDemo`
     - Volley in `VolleyDemo`
     - OkHttp in `OkHttpDemo`

10. **External/runtime boundaries**
   - The only strong external dependencies visible from structure are **Android framework APIs**, **Volley source**, **OkHttp**, and **Gson**.
   - The network-facing demos all cross the same boundary: **app code leaves the process to talk to remote HTTP endpoints or socket peers**, then returns results asynchronously to the main/UI thread.

Main entry points: [`JavaSocketDemo`](https://github.com/xuningjack/androidnet/tree/master/JavaSocketDemo) (Socket demos), [`VolleyDemo`](https://github.com/xuningjack/androidnet/tree/master/VolleyDemo) (Volley demo), [`OkHttpDemo`](https://github.com/xuningjack/androidnet/tree/master/OkHttpDemo) (OkHttp demo), [`WebViewDemo/src/main/java/com/example/david/webviewdemo/WebViewActivity.java`](https://github.com/xuningjack/androidnet/blob/master/WebViewDemo/src/main/java/com/example/david/webviewdemo/WebViewActivity.java) (WebViewActivity)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_plain_java["Plain Java demos"]
  node_java_socket_demo["Socket demos"]
  node_inet_url["Inet/URL<br/>network basics"]
  node_url_read["URL read<br/>[UrlReadDemo.java]"]
  node_single_tcp[("Single TCP<br/>socket pair<br/>[Client.java]")]
  node_multi_tcp[("Multi TCP<br/>socket server<br/>[MultiServer.java]")]
  node_udp_demo[("UDP demo<br/>datagram demo<br/>[UDPServer.java]")]
end

subgraph group_android_apps["Android demos"]
  node_android_http_demo["HTTP demo<br/>android app"]
  node_http_activity["MainActivity<br/>ui entry<br/>[MainActivity.java]"]
  node_webview_demo["WebView demo<br/>android app"]
  node_webview_activity["WebViewActivity<br/>webview host"]
  node_js_bridge["JS bridge<br/>bridge code<br/>[ShowJS.java]"]
  node_volley_demo["Volley demo<br/>android app"]
  node_volley_app["App layer<br/>app glue<br/>[MainActivity.java]"]
  node_custom_volley["Custom Volley<br/>wrapper"]
  node_volley_listener["Callback<br/>listener"]
  node_okhttp_demo["OkHttp demo<br/>android app"]
  node_okhttp_activity["MainActivity<br/>ui entry<br/>[MainActivity.java]"]
  node_okhttp_client[("Client core<br/>http client")]
  node_okhttp_handlers["Handlers<br/>callbacks"]
end

subgraph group_shared_libs["Shared libraries"]
  node_volley_lib["Volley<br/>network library"]
  node_request_queue[("Request queue<br/>dispatch core<br/>[RequestQueue.java]")]
  node_volley_toolbox["Toolbox<br/>request utilities<br/>[Volley.java]"]
end

node_java_socket_demo -->|"includes"| node_inet_url
node_java_socket_demo -->|"includes"| node_url_read
node_java_socket_demo -->|"includes"| node_single_tcp
node_java_socket_demo -->|"includes"| node_multi_tcp
node_java_socket_demo -->|"includes"| node_udp_demo
node_android_http_demo -->|"centers on"| node_http_activity
node_http_activity -.->|"updates UI"| node_android_http_demo
node_webview_demo -->|"centers on"| node_webview_activity
node_webview_activity -->|"bridges to"| node_js_bridge
node_webview_activity -.->|"loads assets"| node_webview_demo
node_volley_lib -->|"contains"| node_request_queue
node_volley_lib -->|"contains"| node_volley_toolbox
node_volley_demo -->|"contains"| node_volley_app
node_volley_demo -->|"wraps"| node_custom_volley
node_volley_demo -->|"uses"| node_volley_listener
node_custom_volley -.->|"uses"| node_volley_lib
node_custom_volley -->|"enqueues"| node_request_queue
node_okhttp_demo -->|"contains"| node_okhttp_activity
node_okhttp_demo -->|"wraps"| node_okhttp_client
node_okhttp_demo -->|"uses"| node_okhttp_handlers
node_okhttp_activity -->|"triggers"| node_okhttp_client
node_okhttp_client -->|"delivers"| node_okhttp_handlers

click node_java_socket_demo "https://github.com/xuningjack/androidnet/tree/master/JavaSocketDemo"
click node_inet_url "https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/com/example/InetAddressDemo.java"
click node_url_read "https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/com/example/UrlReadDemo.java"
click node_single_tcp "https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/http_socket_server_client/single/Client.java"
click node_multi_tcp "https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/http_socket_server_client/multi/MultiServer.java"
click node_udp_demo "https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/udp_socket_server_client/UDPServer.java"
click node_android_http_demo "https://github.com/xuningjack/androidnet/tree/master/AnroidHttpDemo"
click node_http_activity "https://github.com/xuningjack/androidnet/blob/master/AnroidHttpDemo/src/main/java/com/example/david/myapplication/MainActivity.java"
click node_webview_demo "https://github.com/xuningjack/androidnet/tree/master/WebViewDemo"
click node_webview_activity "https://github.com/xuningjack/androidnet/blob/master/WebViewDemo/src/main/java/com/example/david/webviewdemo/WebViewActivity.java"
click node_js_bridge "https://github.com/xuningjack/androidnet/blob/master/WebViewDemo/src/main/java/com/example/david/webviewdemo/ShowJS.java"
click node_volley_lib "https://github.com/xuningjack/androidnet/tree/master/Volley"
click node_request_queue "https://github.com/xuningjack/androidnet/blob/master/Volley/src/com/android/volley/RequestQueue.java"
click node_volley_toolbox "https://github.com/xuningjack/androidnet/blob/master/Volley/src/com/android/volley/toolbox/Volley.java"
click node_volley_demo "https://github.com/xuningjack/androidnet/tree/master/VolleyDemo"
click node_volley_app "https://github.com/xuningjack/androidnet/blob/master/VolleyDemo/src/com/example/volley_demo/MainActivity.java"
click node_custom_volley "https://github.com/xuningjack/androidnet/blob/master/VolleyDemo/src/com/example/volley_demo/CustomVolleyRequest.java"
click node_volley_listener "https://github.com/xuningjack/androidnet/blob/master/VolleyDemo/src/com/example/volley_demo/VolleyListener.java"
click node_okhttp_demo "https://github.com/xuningjack/androidnet/tree/master/OkHttpDemo"
click node_okhttp_activity "https://github.com/xuningjack/androidnet/blob/master/OkHttpDemo/src/main/java/com/example/jack/okhttpdemo/MainActivity.java"
click node_okhttp_client "https://github.com/xuningjack/androidnet/blob/master/OkHttpDemo/src/main/java/com/jack/okhttp/CommonOkHttpClient.java"
click node_okhttp_handlers "https://github.com/xuningjack/androidnet/blob/master/OkHttpDemo/src/main/java/com/jack/okhttp/listener/DisposeDataHandler.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_java_socket_demo,node_inet_url,node_url_read,node_single_tcp,node_multi_tcp,node_udp_demo toneBlue
class node_android_http_demo,node_http_activity,node_webview_demo,node_webview_activity,node_js_bridge,node_volley_demo,node_volley_app,node_custom_volley,node_volley_listener,node_okhttp_demo,node_okhttp_activity,node_okhttp_client,node_okhttp_handlers toneAmber
class node_volley_lib,node_request_queue,node_volley_toolbox toneMint
```

## Components

### Plain Java demos

Core networking examples outside Android UI

- [Socket demos](https://github.com/xuningjack/androidnet/tree/master/JavaSocketDemo): module · Plain Java networking examples for sockets, UDP, and URL primitives · `JavaSocketDemo`
- [Inet/URL](https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/com/example/InetAddressDemo.java): network basics · InetAddress and URL usage examples · `JavaSocketDemo/src/main/java/com/example/InetAddressDemo.java`
- [URL read](https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/com/example/UrlReadDemo.java): url reader · Reads and parses content from a URL · `JavaSocketDemo/src/main/java/com/example/UrlReadDemo.java`
- [Single TCP](https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/http_socket_server_client/single/Client.java): socket pair · Single-client TCP client/server example · `JavaSocketDemo/src/main/java/http_socket_server_client/single/Client.java`
- [Multi TCP](https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/http_socket_server_client/multi/MultiServer.java): socket server · Multi-client TCP server with per-client handling · `JavaSocketDemo/src/main/java/http_socket_server_client/multi/MultiServer.java`
- [UDP demo](https://github.com/xuningjack/androidnet/blob/master/JavaSocketDemo/src/main/java/udp_socket_server_client/UDPServer.java): datagram demo · UDP send/receive example using datagrams · `JavaSocketDemo/src/main/java/udp_socket_server_client/UDPServer.java`

### Android demos

App-level examples using Android UI and platform APIs

- [HTTP demo](https://github.com/xuningjack/androidnet/tree/master/AnroidHttpDemo): android app · Android app showing legacy HTTP APIs · `AnroidHttpDemo`
- [MainActivity](https://github.com/xuningjack/androidnet/blob/master/AnroidHttpDemo/src/main/java/com/example/david/myapplication/MainActivity.java): ui entry · UI entry point that triggers HTTP calls and displays results · `AnroidHttpDemo/src/main/java/com/example/david/myapplication/MainActivity.java`
- [WebView demo](https://github.com/xuningjack/androidnet/tree/master/WebViewDemo): android app · Android app demonstrating embedded browser and JS bridge · `WebViewDemo`
- [WebViewActivity](https://github.com/xuningjack/androidnet/blob/master/WebViewDemo/src/main/java/com/example/david/webviewdemo/WebViewActivity.java): webview host · Activity hosting the embedded WebView runtime · `WebViewDemo/src/main/java/com/example/david/webviewdemo/WebViewActivity.java`
- [JS bridge](https://github.com/xuningjack/androidnet/blob/master/WebViewDemo/src/main/java/com/example/david/webviewdemo/ShowJS.java): bridge code · Java-side bridge object exposed to JavaScript · `WebViewDemo/src/main/java/com/example/david/webviewdemo/ShowJS.java`
- [Volley demo](https://github.com/xuningjack/androidnet/tree/master/VolleyDemo): android app · Example app built on top of Volley · `VolleyDemo`
- [App layer](https://github.com/xuningjack/androidnet/blob/master/VolleyDemo/src/com/example/volley_demo/MainActivity.java): app glue · Application and activity code wiring Volley into the demo UI · `VolleyDemo/src/com/example/volley_demo/MainActivity.java`
- [Custom Volley](https://github.com/xuningjack/androidnet/blob/master/VolleyDemo/src/com/example/volley_demo/CustomVolleyRequest.java): wrapper · App-specific request wrapper around Volley · `VolleyDemo/src/com/example/volley_demo/CustomVolleyRequest.java`
- [Callback](https://github.com/xuningjack/androidnet/blob/master/VolleyDemo/src/com/example/volley_demo/VolleyListener.java): listener · Response callback interface used by the demo app · `VolleyDemo/src/com/example/volley_demo/VolleyListener.java`
- [OkHttp demo](https://github.com/xuningjack/androidnet/tree/master/OkHttpDemo): android app · Android app demonstrating OkHttp plus custom abstractions · `OkHttpDemo`
- [MainActivity](https://github.com/xuningjack/androidnet/blob/master/OkHttpDemo/src/main/java/com/example/jack/okhttpdemo/MainActivity.java): ui entry · App-facing activity that starts requests and updates the UI · `OkHttpDemo/src/main/java/com/example/jack/okhttpdemo/MainActivity.java`
- [Client core](https://github.com/xuningjack/androidnet/blob/master/OkHttpDemo/src/main/java/com/jack/okhttp/CommonOkHttpClient.java): http client · Reusable OkHttp execution and request construction layer · `OkHttpDemo/src/main/java/com/jack/okhttp/CommonOkHttpClient.java`
- [Handlers](https://github.com/xuningjack/androidnet/blob/master/OkHttpDemo/src/main/java/com/jack/okhttp/listener/DisposeDataHandler.java): callbacks · JSON, file, progress, and download response handling · `OkHttpDemo/src/main/java/com/jack/okhttp/listener/DisposeDataHandler.java`

### Shared libraries

Reusable networking infrastructure and vendored code

- [Volley](https://github.com/xuningjack/androidnet/tree/master/Volley): network library · Vendored Volley framework source · `Volley`
- [Request queue](https://github.com/xuningjack/androidnet/blob/master/Volley/src/com/android/volley/RequestQueue.java): dispatch core · Queueing, cache dispatching, network dispatching, and delivery · `Volley/src/com/android/volley/RequestQueue.java`
- [Toolbox](https://github.com/xuningjack/androidnet/blob/master/Volley/src/com/android/volley/toolbox/Volley.java): request utilities · String, JSON, image, and HTTP stack helpers · `Volley/src/com/android/volley/toolbox/Volley.java`

## Connections

- Socket demos → Inet/URL: includes · Module contains primitive network demos
- Socket demos → URL read: includes · Module contains URL reading example
- Socket demos → Single TCP: includes · Module contains single-client TCP example
- Socket demos → Multi TCP: includes · Module contains multi-client TCP example
- Socket demos → UDP demo: includes · Module contains UDP example
- HTTP demo → MainActivity: centers on · Activity drives legacy HTTP requests
- MainActivity → HTTP demo: updates UI · Network results are rendered back in the activity
- WebView demo → WebViewActivity: centers on · Activity hosts the embedded browser
- WebViewActivity → JS bridge: bridges to · WebView exposes Java bridge for JS calls
- WebViewActivity → WebView demo: loads assets · Activity loads bundled HTML content
- Volley → Request queue: contains · Core queueing, cache, network, and delivery pipeline
- Volley → Toolbox: contains · Higher-level request and HTTP helpers
- Volley demo → App layer: contains · App entry and wiring code
- Volley demo → Custom Volley: wraps · App-specific request abstraction over Volley
- Volley demo → Callback: uses · Callbacks return responses to the UI layer
- Custom Volley → Volley: uses · Wrapper delegates to Volley internals
- Custom Volley → Request queue: enqueues · Requests flow into Volley RequestQueue
- OkHttp demo → MainActivity: contains · App-facing UI entry point
- OkHttp demo → Client core: wraps · Reusable transport layer around OkHttp
- OkHttp demo → Handlers: uses · Response and download handling
- MainActivity → Client core: triggers · Activity starts HTTP requests through the wrapper
- Client core → Handlers: delivers · Responses are dispatched through listener/handler code
