net.nutss.stunt
Class STUNTEndpoint

java.lang.Object
  extended by net.nutss.stunt.STUNTEndpoint

public class STUNTEndpoint
extends Object

Implements a STUNT TCP endpoint. The same class is used for both TCP server sockets and TCP client sockets. accept() and connect() operations are asyncronous and reported via a callback mechanism. Instead of IP addresses and ports, the user-visible address is a URI which can be unique even in the presence of NATs.


Nested Class Summary
private static class STUNTEndpoint.Worker
          The real class that implements the STUNT endpoint.
 
Field Summary
private  STUNTEndpoint.Worker worker
          Real worker thread
 
Constructor Summary
STUNTEndpoint()
          Creates a new STUNT endpoint bound to the local user and hostname.
STUNTEndpoint(URI id)
          Creates a new STUNT endpoint bound to the given URI.
 
Method Summary
 void close()
          Closes the endpoint.
 void connect(URI dst, STUNTEventListener cb)
          Initiate an outgoing connection
 void listen(STUNTEventListener cb)
          Marks this endpoint as willing to receive incoming connections
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

worker

private STUNTEndpoint.Worker worker
Real worker thread

Constructor Detail

STUNTEndpoint

public STUNTEndpoint()
              throws IOException
Creates a new STUNT endpoint bound to the local user and hostname.

Throws:
IOException - if endpoint couldn't bind

STUNTEndpoint

public STUNTEndpoint(URI id)
              throws IOException
Creates a new STUNT endpoint bound to the given URI. If id is null, binds to a random name based on the local username and hostname.

Parameters:
id - the local address
Throws:
IOException - if endpoint couldn't bind
Method Detail

listen

public void listen(STUNTEventListener cb)
            throws IOException
Marks this endpoint as willing to receive incoming connections

Parameters:
cb - the callback functions to call for accept()
Throws:
IOException - if the socket has already been closed, or already listening

connect

public void connect(URI dst,
                    STUNTEventListener cb)
             throws IOException
Initiate an outgoing connection

Parameters:
dst - destination ID
cb - callback for success or failure
Throws:
IOException - if the endpoint has been closed

close

public void close()
Closes the endpoint.