Skip to content

About

TCP socket server codelab for HarmonyOS watches implementing a local HTTP echo server with on-screen request logging.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Note: To access all shared projects, get information about environment setup, and view other guides, please visit Explore-In-HMOS-Wearable Index.

How to implement a TCP Server

This project is an educational project designed to demonstrate how to implement a web server on Huawei wearable devices using socket connections. This codelab serves as a foundational tutorial for developers who want to understand network communication capabilities on HarmonyOS wearables.

When launched, the application starts a local HTTP server on the wearable device. The server logs all incoming requests to the device screen and responds with an echo containing all the request parameters and data it received.

The key learning objective is to understand socket-based web server implementation on wearable platforms, providing the foundation for more complex networked wearable applications.

Preview

Use Cases

Ideal for learning web server fundamentals on wearable devices, prototyping IoT applications, understanding HarmonyOS networking capabilities, and serving as a foundation for building more complex networked wearable applications. This codelab demonstrates that even constrained wearable devices can function as capable network endpoints.

Technology

Stack

  • Languages: ArkTS, ArkUI
  • Frameworks: HarmonyOS SDK 5.0.2(14)
  • Tools: DevEco Studio Vers 5.1.0.820
  • Libraries: @kit.ArkUI, @kit.NetworkKit

Testing the Web Server

To test the web server functionality on real devices, follow these steps:

Prerequisites

  • Server and client must be connected same Wi-Fi network
  • HTTP client (browser, curl, or Postman) for testing

Setup Instructions

  1. Launch the app on the watch - the web server will start automatically

  2. Test the server from your local machine:

    # Simple GET request
    curl http://localhost:6060
    
    # POST request with data
    curl -X POST http://localhost:6060/test -d "key=value&name=example"
    
    # GET request with query parameters
    curl http://localhost:6060/api?param1=hello&param2=world
  3. Observe the results:

    • Watch the wearable screen to see logged request details
    • Check the HTTP response containing echoed request parameters

Network Architecture

The host computer acts as a bridge, forwarding HTTP requests from your local machine to the watch's web server through port mapping.

Directory Structure

entry/src/main/ets/
├───entryability
│       EntryAbility.ets
├───entrybackupability
│       EntryBackupAbility.ets
├───lib
│       http_server.ts
├───pages
│       Index.ets
└───

Constraints and Restrictions

Supported Device

  • Huawei Watch 5

LICENSE

Wearable Web Server is distributed under the terms of the MIT License. See the license for more information.

About

TCP socket server codelab for HarmonyOS watches implementing a local HTTP echo server with on-screen request logging.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages