How xuningjack/androidnet works
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 Socket demos · VolleyDemo Volley demo · OkHttpDemo OkHttp demo · WebViewActivity.java WebViewActivity
Components 22
Plain Java demos
Core networking examples outside Android UI
- Socket demos · Plain Java networking examples for sockets, UDP, and URL primitives
JavaSocketDemo - Inet/URL · InetAddress and URL usage examples
JavaSocketDemo/src/main/java/com/example/InetAddressDemo.java - URL read · Reads and parses content from a URL
JavaSocketDemo/src/main/java/com/example/UrlReadDemo.java - Single TCP · Single-client TCP client/server example
JavaSocketDemo/src/main/java/http_socket_server_client/single/Client.java - Multi TCP · Multi-client TCP server with per-client handling
JavaSocketDemo/src/main/java/http_socket_server_client/multi/MultiServer.java - UDP 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 · Android app showing legacy HTTP APIs
AnroidHttpDemo - MainActivity · UI entry point that triggers HTTP calls and displays results
AnroidHttpDemo/src/main/java/com/example/david/myapplication/MainActivity.java - WebView demo · Android app demonstrating embedded browser and JS bridge
WebViewDemo - WebViewActivity · Activity hosting the embedded WebView runtime
WebViewDemo/src/main/java/com/example/david/webviewdemo/WebViewActivity.java - JS bridge · Java-side bridge object exposed to JavaScript
WebViewDemo/src/main/java/com/example/david/webviewdemo/ShowJS.java - Volley demo · Example app built on top of Volley
VolleyDemo - App layer · Application and activity code wiring Volley into the demo UI
VolleyDemo/src/com/example/volley_demo/MainActivity.java - Custom Volley · App-specific request wrapper around Volley
VolleyDemo/src/com/example/volley_demo/CustomVolleyRequest.java - Callback · Response callback interface used by the demo app
VolleyDemo/src/com/example/volley_demo/VolleyListener.java - OkHttp demo · Android app demonstrating OkHttp plus custom abstractions
OkHttpDemo - MainActivity · App-facing activity that starts requests and updates the UI
OkHttpDemo/src/main/java/com/example/jack/okhttpdemo/MainActivity.java - Client core · Reusable OkHttp execution and request construction layer
OkHttpDemo/src/main/java/com/jack/okhttp/CommonOkHttpClient.java - Handlers · 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 · Vendored Volley framework source
Volley - Request queue · Queueing, cache dispatching, network dispatching, and delivery
Volley/src/com/android/volley/RequestQueue.java - Toolbox · String, JSON, image, and HTTP stack helpers
Volley/src/com/android/volley/toolbox/Volley.java
Connections 22
- 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