dart:io library

Important: Browser-based applications can't use this library.
Only servers, command-line scripts, and Flutter mobile apps can import
and use dart:io.

This library allows you to work with files, directories,
sockets, processes, HTTP servers and clients, and more.
Many operations related to input and output are asynchronous
and are handled using Futures or Streams, both of which
are defined in the dart:async
library.

Many methods provided by the File, Directory, and Link classes
run asynchronously and return a Future.

FileSystemEntity

File, Directory, and Link all extend FileSystemEntity.
In addition to being the superclass for these classes,
FileSystemEntity has a number of static methods for working with paths.

To get information about a path,
you can use the FileSystemEntity static methods
such as 'isDirectory', 'isFile', and 'exists'.
Because file system access involves I/O, these methods
are asynchronous and return a Future.

FileSystemEntity.isDirectory(myPath).then((isDir) {
if (isDir) {
print('$myPath is a directory');
} else {
print('$myPath is not a directory');
}
});

HttpServer and HttpClient

The HttpServer class provides the basic functionality for
implementing an HTTP server.
For some higher-level building-blocks, we recommend that you try
the shelf
pub package, which contains
a set of high-level classes that, together with the HttpServer class
in this library, make it easier to implement HTTP servers.

Process

The Process class provides a way to run a process on
the native machine.
For example, the following code spawns a process that recursively lists
the files under web.

Using start() returns a Future, which completes with a Process object
when the process has started. This Process object allows you to interact
with the process while it is running. Using run() returns a Future, which
completes with a ProcessResult object when the spawned process has
terminated. This ProcessResult object collects the output and exit code
from the process.

When using start(),
you need to read all data coming on the stdout and stderr streams otherwise
the system resources will not be freed.

WebSocket

The WebSocket class provides support for the web socket protocol. This
allows full-duplex communications between client and server applications.

A web socket server uses a normal HTTP server for accepting web socket
connections. The initial handshake is a HTTP request which is then upgraded to a
web socket connection.
The server upgrades the request using WebSocketTransformer
and listens for the data on the returned web socket.
For example, here's a mini server that listens for 'ws' data
on a WebSocket:

Check out the
websocket_sample
app, which uses WebSockets to communicate with a server.

Socket and ServerSocket

Clients and servers use Sockets to communicate using the TCP protocol.
Use ServerSocket on the server side and Socket on the client.
The server creates a listening socket using the bind() method and
then listens for incoming connections on the socket. For example:

Representation of a cookie. For cookies received by the server as
Cookie header values only name and value fields will be
set. When building a cookie for the 'set-cookie' header in the server
and when receiving cookies in the client as 'set-cookie' headers all
fields can be used.

When detaching a socket from either the HttpServer or the
HttpClient due to a HTTP connection upgrade there might be
unparsed data already read from the socket. This unparsed data
together with the detached socket is returned in an instance of
this class.

This class facilitates overriding HttpClient with a mock implementation.
It should be extended by another class in client code with overrides
that construct a mock implementation. The implementation in this base class
defaults to the actual HttpClient implementation. For example: [...]

RawSecureSocket provides a secure (SSL or TLS) network connection.
Client connections to a server are provided by calling
RawSecureSocket.connect. A secure server, created with
RawSecureServerSocket, also returns RawSecureSocket objects representing
the server end of a secure connection.
The certificate provided by the server is checked
using the trusted certificates set in the SecurityContext object.
The default SecurityContext object contains a built-in set of trusted
root certificates for well-known certificate authorities.

A high-level class for communicating securely over a TCP socket, using
TLS and SSL. The SecureSocket exposes both a Stream and an
IOSink interface, making it ideal for using together with
other Streams.