test aria2 on windows platform

 

 

import 'dart:io';
import 'dart:convert';
import 'package:path/path.dart';
import 'package:web_socket_channel/io.dart';

//https://dldir1.qq.com/qqfile/qq/PCQQ9.1.3/25323/QQ9.1.3.25323.exe

String gid = '';
bool firstRun = true;

main()async{
  print('1');
  createConnection();

  print('2');
  await Future.delayed(Duration(seconds: 1));
  createConnection();

  print('3');
  await Future.delayed(Duration(seconds: 1));
  createConnection();


  String url = 'https://dldir1.qq.com/qqfile/qq/PCQQ9.1.3/25323/QQ9.1.3.25323.exe';

  var s = IOWebSocketChannel.connect('ws://localhost:6800/jsonrpc');
  s.stream.listen(onData, onDone: onDone, one rror: one rror);
  Map task = {"jsonrpc":"2.0","id":"m","method":"aria2.addUri","params":["token:studyaria2",["$url"]]};
  s.sink.add(json.encode(task));

  await Future.delayed(Duration(seconds: 1));
  while(true){
    checkStatus(s, gid);
    await Future.delayed(Duration(seconds: 1));
  }
  
  

}

checkStatus(IOWebSocketChannel channel, String gid){
  Map task = {"jsonrpc":"2.0","id":"m","method":"aria2.tellStatus",
    "params":[
      "token:studyaria2",
      "$gid",
      ["gid", "status", "totalLength", "completedLength", "downloadSpeed","files"]
    ]
  };
  channel.sink.add(json.encode(task));
}

createConnection()async{
  String aria2 = 'C:\\Users\\gshao\\aria2\\aria2c';
  var a = await Process.run(aria2, [r'--conf-path=C:\Users\gshao\aria2\aria2.conf']);
  await Future.delayed(Duration(seconds: 1));
  var xx = await a.exitCode;
  print('create ok 1: $a');
  print('create ok 2 status: ${a.stdout}');
  print('create ok 3 error:${a.stderr}');
  print('create ok 4 exitcode:,');
}

onData(v){
  print('onData: $v');
  if(firstRun){
    gid = json.decode(v)['result'];
    firstRun = false;
    print('gid:::::::::::: $gid');
  }

}

onDone(){
  print('1, done');
}

onError(e){
  print('2, error: ${e.toString()}');
}

  

上一篇:iOS阶段学习第14天笔记(NSString与NSMutableString)


下一篇:layDate关闭方法