Chapter 5. Walkthrough: Dartiverse Search

This chapter points out some of the useful and fun features of the Dart language and libraries that are used in Dartiverse Search, a client-server app. As Figure 5-1 shows, Dartiverse Search looks for a user-entered string in GitHub and StackOverflow. The app is asynchronous, adding results as they’re found, so the UI is always responsive.

The client app UI
Figure 5-1. The client app UI

How to Run Dartiverse Search

You can use Dart Editor to get and run Dartiverse Search:

  1. In Dart Editor, go to the Welcome page. (If you don’t see it, choose ToolsWelcome Page.)

  2. In the demo section, click Dartiverse Search to create a copy of the dartiverse_search package.[2]

  3. Use ToolsPub Build to build the package.

  4. Select bin/server.dart and click the Run button. You should see a message that the search server is running at http://127.0.0.1:9223/.

  5. Click that URL or enter it into any modern browser. The search client UI should appear in your default browser.

How Dartiverse Search Works

The search server is an HTTP server that provides a WebSocket interface. The search client uses that WebSocket interface as a bi-directional communication channel with the server. The client sends search requests to the server over the WebSocket, and the server replies with any results and then a final, “search done” message.

The server starts things off by binding to localhost, port 9223, and listening ...

Get Dart: Up and Running now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.