Written by Peter Lipay as part of his Undergraduate Thesis at the University of Washington. June 2010.
Terms of Use:
You are free to use this library in any of your applications, as long as you do not try
to claim it as your own. Please keep the mention of the original creator in the comments
at the top of the library classes.
This is an early experimental build of the protocol. It has performed well in my tests, but
it has not undergone testing on a wide range of machines/connections, and is by no means
guaranteed to work in all circumstances, so it goes without saying that I am not liable for
any damage or unintended consequences from the use of this library.
Description:
This UTP library allows Java Developers to use the UTP protocol in their applications.
UTP is meant as an alternative to TCP, and is geared primarily for Low-Priority Networking applications.
In the absence of competing network traffic, UTP connections will try to maximize bandwidth (though
there is a small penalty because they try to keep latency down) , but when competing traffic
appears on the network (for instance, Web Browsing or VoIP traffic), the UTP connections will yield
the connection, minimizing the effect of the application on the user. More specific implementation
details can be found in this draft specification (which I've followed for the most part):
http://www.bittorrent.org/beps/bep_0029.html
This implementation is meant as an alternative to java's Socket and ServerSocket classes.
UTPSocket and UTPServerSocket are basic complements to the Socket and ServerSocket classes,
albeit with significantly stripped down feature-sets.
Installation/Use:
Copy UTPSocket, UTPServerSocket, and UTPPacket to your project directory, and compile them.
For server applications, create an instance of UTPServerSocket, passing in the port number you
want it to listen on as an argument to the constructor. Then call the listen() function,
which will wait for incoming UTP connections and return a UTPSocket if a connection is established.
For client applications, create an instance of the UTPSocket class, passing in the hostname and port number
that you want to connect to. If a connection cannot be established, an Exception will be thrown by the constructor,
otherwise, the socket is connected and functioning.
In both cases, once you have a connected Socket, you can call getInputStream() to get an InputStream
to read incoming data from the socket, and getOutputStream() to get an OutputStream to write to the socket.
The InputStream and OutputStream classes are very basic, and currently each support one real function call.
You can call read() on InputStream to read a byte from the socket, and you can call write(int x) on OutputStream
to write a byte to the socket.
When you are finished with the connection, you can call close() on a UTPSocket to terminate the connection.
To see an example of how to use UTPSocket and UTPServerSocket, look at utpclient and utpserver in the Examples folder.
Note: Currently, the UTP Socket implementation doesn't send still-alive packets, so if the sender abruptly terminates
the connection, the receiver will not be aware of this until it tries to send packets to the sender