Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Unified Diff: sdk/lib/io/socket.dart

Issue 85993002: Add UDP support to dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows build Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/lib/io_patch.dart ('k') | tests/standalone/io/raw_datagram_socket_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/socket.dart
diff --git a/sdk/lib/io/socket.dart b/sdk/lib/io/socket.dart
index 2f789585e6ca4313485ed1cdc31a981035734921..b619feccd940f44ca7cef75652b6f43d258cd445 100644
--- a/sdk/lib/io/socket.dart
+++ b/sdk/lib/io/socket.dart
@@ -323,6 +323,11 @@ class SocketOption {
*/
static const SocketOption TCP_NODELAY = const SocketOption._(0);
+ static const SocketOption _IP_MULTICAST_LOOP = const SocketOption._(1);
+ static const SocketOption _IP_MULTICAST_HOPS = const SocketOption._(2);
+ static const SocketOption _IP_MULTICAST_IF = const SocketOption._(3);
+ static const SocketOption _IP_BROADCAST = const SocketOption._(4);
+
const SocketOption._(this._value);
final _value;
}
@@ -506,6 +511,136 @@ abstract class Socket implements Stream<List<int>>, IOSink {
}
+/**
+ * Datagram package. Data send to and received from datagram sockets
+ * contains the internet address and port of the destination or source
+ * togeter with the data.
+ */
+class Datagram {
+ List<int> data;
+ InternetAddress address;
+ int port;
+
+ Datagram(this.data, this.address, this.port);
+}
+
+
+/**
+ * The [RawDatagramSocket] is a low-level interface to an UDP socket,
+ * exposing the raw events signaled by the system. It's a [Stream] of
+ * [RawSocketEvent]s.
+ *
+ * Note that the event [RawSocketEvent.READ_CLOSED] will never be
+ * received as an UDP socket cannot be closed by a remote peer.
+ */
+abstract class RawDatagramSocket extends Stream<RawSocketEvent> {
+ /**
+ * Creates a new raw datagram socket binding it to an address and
+ * port.
+ */
+ external static Future<RawDatagramSocket> bind(
+ host, int port, {bool reuseAddress: true});
+
+ /**
+ * Returns the port used by this socket.
+ */
+ int get port;
+
+ /**
+ * Returns the address used by this socket.
+ */
+ InternetAddress get address;
+
+ /**
+ * Close the datagram socket.
+ */
+ void close();
+
+ /**
+ * Send a datagram.
+ *
+ * Returns the number of bytes written. This will always be either
+ * the size of [buffer] or `0`.
+ */
+ int send(List<int> buffer, InternetAddress address, int port);
+
+ /**
+ * Receive a datagram. If there are no datagrams available `null` is
+ * returned.
+ */
+ Datagram receive();
+
+ /**
+ * Join a multicast group.
+ *
+ * If an error occur when trying to join the multicast group an
+ * exception is thrown.
+ */
+ void joinMulticast(InternetAddress group, {NetworkInterface interface});
+
+ /**
+ * Leave a multicast group.
+ *
+ * If an error occur when trying to join the multicase group an
+ * exception is thrown.
+ */
+ void leaveMulticast(InternetAddress group, {NetworkInterface interface});
+
+ /**
+ * Set or get, if the [RawDatagramSocket] should listen for
+ * [RawSocketEvent.READ] events. Default is [true].
+ */
+ bool readEventsEnabled;
+
+ /**
+ * Set or get, if the [RawDatagramSocket] should listen for
+ * [RawSocketEvent.WRITE] events. Default is [true]. This is a
+ * one-shot listener, and writeEventsEnabled must be set to true
+ * again to receive another write event.
+ */
+ bool writeEventsEnabled;
+
+ /**
+ * Set or get, whether multicast traffic is looped back to the host.
+ *
+ * By default multicast loopback is enabled.
+ */
+ bool multicastLoopback;
+
+ /**
+ * Set or get, the maximum network hops for multicast packages
+ * originating from this socket.
+ *
+ * For IPv4 this is referred to as TTL (time to live).
+ *
+ * By default this value is 1 causing multicast traffic to stay on
+ * the local network.
+ */
+ int multicastHops;
+
+ /**
+ * Set or get, the network interface used for outgoing multicast packages.
+ *
+ * A value of `null`indicate that the system chooses the network
+ * interface to use.
+ *
+ * By default this value is `null`
+ */
+ NetworkInterface multicastInterface;
+
+ /**
+ * Set or get, whether IPv4 broadcast is enabled.
+ *
+ * IPv4 broadcast needs to be enabled by the sender for sending IPv4
+ * broadcast packages. By default IPv4 broadcast is disabled.
+ *
+ * For IPv6 there is no general broadcast mechanism. Use multicast
+ * instead.
+ */
+ bool broadcastEnabled;
+}
+
+
class SocketException implements IOException {
final String message;
final OSError osError;
« no previous file with comments | « sdk/lib/_internal/lib/io_patch.dart ('k') | tests/standalone/io/raw_datagram_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698