Session

public class Session

The class representing Carrier session conversion with friends.

Methods

addService

public void addService(String service, PortForwardingProtocol protocol, String host, String port)

Add a new portforwarding service to session. The registered services can be used by remote peer in portforwarding request.

Parameters
  • service – The new service name, should be unique in session scope

  • protocol – The protocol of the service

  • host – The host name or ip of the service

  • port – The port of the service

Throws

addStream

public Stream addStream(StreamType type, int options, StreamHandler handler)

Add a new stream to session. Carrier stream supports several underlying transport mechanisms: - Plain/encrypted UDP data gram protocol - Plain/encrypted TCP like reliable stream protocol - Multiplexing over UDP - Multiplexing over TCP like reliable protocol Application can use options to specify the new stream mode. Multiplexing over UDP can not provide reliable transport.

Parameters
  • type – The stream type defined in StreamType

  • options – The stream mode options. options are constructed by a bitwise-inclusive OR of flags

  • handler – The Application defined inerface to StreamHandler

Throws
Returns

The new added carrier stream

close

public synchronized void close()

Close a session to friend. All resources include streams, channels, portforwardings associated with current session will be destroyed.

finalize

protected void finalize()

getPeer

public String getPeer()

Get remote peer id.

Returns

The remote peer userid.

removeService

public void removeService(String service)

Remove a portforwarding server to session. This function has not effect on existing portforwarings.

Parameters
  • service – The service name.

removeStream

public void removeStream(Stream stream)

Remove a stream from session.

Parameters
  • stream – The Stream to be removed

Throws

replyRequest

public void replyRequest(int status, String reason)

Reply the session request from friend. This function will send a session response to friend.

Parameters
  • status – The status code of the response. 0 is success, otherwise is error

  • reason – The error message if status is error, or null if success

Throws

request

public void request(SessionRequestCompleteHandler handler)

Send session request to the friend.

Parameters
  • handler – A handler to the SessionRequestCompleteHandler to receive the session response

Throws

start

public void start(String sdp)

Begin to start a session. All streams in current session will try to connect with remote friend, The stream status will update to application by stream’s StreamHandler.

Parameters
Throws