public final class IncomingConnection

  1. Object
  2. IncomingConnection

An incoming request from another device that wants to connect, delivered to TransportListener.connectionRequested.

Named IncomingConnection rather than the obvious ConnectionRequest because com.codename1.io.ConnectionRequest is one of the most widely used classes in the framework, and an app doing both networking and nearby transport – which is most of them – would have had to qualify one of the two at every mention.

Answer it with accept() or reject(). A request that is never answered times out on the far side, so answer every one – and answer it promptly, because both platforms hold radio resources open meanwhile.

Show the token

getAuthenticationToken() is a short string both devices compute from the connection, and it is the only defense against a device in the middle pretending to be the one the user meant. Showing it on both screens and asking “do these match?” is what makes the pairing trustworthy; skipping that step is a choice to trust whoever answered first.

Methods

public Endpoint getEndpoint()Who is asking.
public String getAuthenticationToken()The short string both devices derive from this connection’s key exchange.
public boolean isAnswered()Whether accept() or reject() has already been called.
public void accept()Accepts the connection.
public void reject()Rejects the connection.
public String toString()Returns a string representation of the object.

Inherited methods

Method details

getEndpoint

public Endpoint getEndpoint()
Who is asking.

getAuthenticationToken

public String getAuthenticationToken()

The short string both devices derive from this connection’s key exchange. Identical on both sides when nothing is in the middle.

Never null, and empty on iOS: MultipeerConnectivity offers no material to bind a token to, and inventing one from the service name and display names would produce matching digits at both ends of a relay. Treat empty as “this platform cannot answer the question”.

isAnswered

public boolean isAnswered()
Whether accept() or reject() has already been called.

accept

public void accept()
Accepts the connection. The result arrives as TransportListener.connected or TransportListener.connectionFailed, because the far side has to accept too. Calling this twice, or after reject(), does nothing.

reject

public void reject()
Rejects the connection. Calling this twice, or after accept(), does nothing.

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())