O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using sockets

At a somewhat lower level in the OSI model than HTTP clients and servers, we find sockets. They also enable interprocess communications across a network between clients and servers and are implemented on top of the TCP/IP. The classes that offer that functionality can be again found in dart:io as follows:

  • Socket: This is used by a client to establish a connection to a server
  • ServerSocket: This is used by a server to accept client connections

How to do it...

The following steps will show you how to make a server socket work:

  1. The following is the code for the server (see the project sockets, socket_server.dart):
    import 'dart:io'; import 'dart:convert'; InternetAddress HOST = InternetAddress.LOOPBACK_IP_V6; const PORT = 7654; void main() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required