RawSocketEvent class
Events for the RawDatagramSocket, RawSecureSocket, and RawSocket.
These event objects are used by the Stream behavior of the sockets (for example RawSocket.listen, RawSocket.forEach) when the socket's state change.
import 'dart:convert';
import 'dart:io';
void main() async {
final socket = await RawSocket.connect("example.com", 80);
socket.listen((event) {
switch (event) {
case RawSocketEvent.read:
final data = socket.read();
if (data != null) {
print(ascii.decode(data));
}
break;
case RawSocketEvent.write:
socket.write(ascii.encode('GET /\r\nHost: example.com\r\n\r\n'));
socket.writeEventsEnabled = false;
break;
case RawSocketEvent.readClosed:
socket.close();
break;
case RawSocketEvent.closed:
break;
default:
throw "Unexpected event $event";
}
});
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- closed → const RawSocketEvent
- An event indicates the socket is closed.
- read → const RawSocketEvent
- An event indicates the socket is ready to be read.
- readClosed → const RawSocketEvent
- An event indicates the reading from the socket is closed
- write → const RawSocketEvent
- An event indicates the socket is ready to write.