Dart API Referencedart:ioSocket

Socket Interface

Extends

Hashable

Constructors

Code new Socket(String host, int port) #

Constructs a new socket and initiate connecting it to the given host on the given port. The returned socket is not yet connected but ready for registration of callbacks.

Socket(String host, int port);

Methods

Code int available() #

Returns the number of received and non-read bytes in the socket that can be read.

int available();

Code void close([bool halfClose]) #

Closes the socket. Calling close will never throw an exception and calling it several times is supported. If halfClose is true the socket will only be closed for writing and it might still be possible to read data. Calling close will not trigger a call to onClosed.

void close([bool halfClose]);

Code int hashCode() #

Socket is hashable.

int hashCode();

Code InputStream get inputStream() #

Returns input stream to the socket.

InputStream get inputStream();

Code void set onClosed(void callback()) #

The close handler gets called when a the last byte have been read from a socket. At this point the socket might still be open for writing for sending more data.

void set onClosed(void callback());

Code void set onConnect(void callback()) #

The connect handler gets called when connection to a given host succeeded.

void set onConnect(void callback());

Code void set onData(void callback()) #

The data handler gets called when data becomes available at the socket.

void set onData(void callback());

Code void set onError(void callback(e)) #

The error handler gets called when a socket error occurs.

void set onError(void callback(e));

Code void set onWrite(void callback()) #

The write handler gets called once when the socket becomes available for writing. Then the handler is automatically reset to null. This handler is mainly used when writeList has reported an incomplete write, to schedule writing the remaining data to the socket.

void set onWrite(void callback());

Code OutputStream get outputStream() #

Returns output stream of the socket.

OutputStream get outputStream();

Code int get port() #

Returns the port used by this socket.

int get port();

Code int readList(List<int> buffer, int offset, int count) #

Reads up to count bytes of data from the socket and stores them into buffer after buffer offset offset. The number of successfully read bytes is returned. This function is non-blocking and will only read data if data is available.

int readList(List<int> buffer, int offset, int count);

Code String get remoteHost() #

Returns the remote host connected to by this socket.

String get remoteHost();

Code int get remotePort() #

Returns the remote port connected to by this socket.

int get remotePort();

Code int writeList(List<int> buffer, int offset, int count) #

Writes up to count bytes of the buffer from offset buffer offset to the socket. The number of successfully written bytes is returned. This function is non-blocking and will only write data if buffer space is available in the socket.

int writeList(List<int> buffer, int offset, int count);