StreamHandler

public interface StreamHandler

The interface to carrier stream instance. Include stream status callback, stream data callback, and channel callbacks.

Methods

onChannelClose

void onChannelClose(Stream stream, int channel, CloseReason reason)

The callback function to be called when channel close.

Parameters
  • stream – The carrier stream instance

  • channel – The current channel ID.

  • reason – Channel close reason code, defined in CloseReason.

onChannelData

boolean onChannelData(Stream stream, int channel, byte[] data)

The callback functiont to be called when channel received incoming data.

Parameters
  • stream – The carrier stream instance

  • channel – The current channel ID

  • data – The received data

Returns

True on success, or false if an error occurred. If this callback return false, the channel will be closed with CloseReason_Error.

onChannelOpen

boolean onChannelOpen(Stream stream, int channel, String cookie)

The callback function to be called when new multiplexing channel request to open.

Parameters
  • stream – The carrier stream instance

  • channel – The current channel ID.

  • cookie – Application defined string data send from remote peer.

Returns

True on success, or false if an error occurred. The channel will continue to open only this callback return true, otherwise the channel will be closed.

onChannelOpened

void onChannelOpened(Stream stream, int channel)

The callback function to be called when new multiplexing channel opened.

Parameters
  • stream – The carrier stream instance

  • channel – The current channel ID

onChannelPending

void onChannelPending(Stream stream, int channel)

The callback function to be called when remote peer ask to pend data sending.

Parameters
  • stream – The carrier stream instance

  • channel – The current channel ID

onChannelResume

void onChannelResume(Stream stream, int channel)

The callback function to be called when remote peer ask to resume data sending.

Parameters
  • stream – The carrier stream instance

  • channel – The current channel ID

onStateChanged

void onStateChanged(Stream stream, StreamState state)

The callback function to report state of stream when it’s state changes.

Parameters
  • stream – The carrier stream instance

  • state – Stream state defined in StreamState

onStreamData

void onStreamData(Stream stream, byte[] data)

The callback will be called when the stream receives incoming packet. If the stream enabled multiplexing mode, application will not receive stream-layered data callback any more. All data will reported as multiplexing channel data.

Parameters
  • stream – The carrier stream instance

  • data – The received packet data