utp_protocol

Creator: coderz1093

Last updated:

0 purchases

utp_protocol Image
utp_protocol Images

Languages

Categories

Add to Cart

Description:

utp protocol

About #
This library implements uTorrent Transport Protocol with pure Dart , no any other native library.
More uTP informations please take a look BEP 0029.
How to use #
UTP socket include ServerUTPSocket and UTPSocketClient.
Listening income connection: #
var serverSocket = await ServerUTPSocket.bind(InternetAddress.anyIPv4, portyoulike);

serverSocket.listen((socket) {
print('someone connect me');
socket.listen((data) {
// receive data
});
});
copied to clipboard
Connect remote: #
var client = UTPSocketClient();
var socket = await client.connect(remoteAddress, remotePort);

socket.listen((data) {
// receive data
});
copied to clipboard
Each UTPSocketClient can create mulitple UTP socket via connect method and each UTP socket share the same raw UDP socket , user can set the max UTP socket number (default is 5) when create UTPSocketClient instance.
Send data: #
socket.write(sometext); // write some text
socket.writeln(sometext); // write some text with \n
// write mulitple text together and sperate with ','
socket.writeAll(sometextList,',');
socket.add(somebyteslist); // send some List<int> data
copied to clipboard
The default text encoding is UTF-8 , user can set the encoding:
socket.encoding = someencoding;
copied to clipboard
Even UTP socket use UDP to delivery the datas , but the UTP socket won't send the data 'one-by-one' , it will add the data into sending buffer , once there is avalidate window size , the socket will read the buffer data out with the avalidate size(less than the max packet size) and packet them together to send out.
on the other hand , If the sending data methods(add,write,etc...) are invoked in the same tick , these sending datas will be added in a cache , the socket will request to send them next tick.
For example:
socket.write('u');
socket.write('T');
socket.write('P');
copied to clipboard
These methods are invoke in same tick , these datas ('u','T','P') will add into a cache (become 'uTP') and will be send next tick.
But it not means that remote will receive the 'uTP' in one packet , it depends the current window size.
Receive(listening) data: #
socket.listen((Uint8List data) {
// receive data
},
onDone : (){
// when remote or local socket closed , this method will be invoke
},
onError:(e){
// when error happen,invoke this method
});
copied to clipboard
Close the socket: #
await socket.close();
copied to clipboard
When invode the close method , the socket will send ST_FIN message to remote and waiting for the ack from remote , if user want to close it immediately , you can call this method :
socket.destroy();
copied to clipboard
Actually , destroy method will send ST_RESET message to remote ,but it won't wait the ACK.
If socket close , it will wait for the expect ACK seq number, when the correct seq number received , the close method will completed future , or it will complete the future when timeout

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.