Skip to content
Horusiath edited this page May 10, 2012 · 17 revisions

Here we will show, you how easy and fun could be a programming with UTorri.

How to begin

Lets start from basic example. To comunicate with uTorrent application remotely, firstly we need to create a UTorri.Client.RemoteClient object. It is responsible for access, authorize and processing all request-response events.

var client = new RemoteClient("localhost", 20000, "username", "password");
client.ConnectionOpened += OnConnectionOpen;
client.OpenAsync();

As the RemoteClient implements IDisposable interface, it's recommended to invoke Dispose method after all of it's operations will end.

Arguments passed to constructor are:

  • Address of the machine, we want to connect to. All communication proceeds using HTTP protocol.
  • Listening port of uTorrent application.
  • uTorrent remote identity - user name.
  • uTorrent remote identity - password.

There are few variances of constructor definitions, all of them based on url and credentials data.

As we said before, all of the API specyfic methods are based on asynchronous requests. Due to that fact we created a ConnectionOpened event, which singalizes when the connection has been initialized successfuly. Finaly OpenAsync method performs initial request and check authorizes remote access by credentials passed previously inside the constructor.

Receiving data

So, now we have initialized the connection. Now it's time to get some data. Using our client from previous code, we just need to write:

client.GetTorrentList(torrents => /* here we do the work */ );

We can see now, how the operations calls works. Firstly we call GetTorrentList method, which creates an asynchronous request for actual list of torrents shown in associated uTorrent application on the second end of remote connection. If you look at the definition of this method, you will see, that it's not returning anything. Instead of that we can pass a callback method, which will be invoked, when the response arrives. There is also no need to parse incoming response, because UTorri will automagically create a valid .NET object for us.

Note that when you want to update an application view from within the argument action, you have to use a Dispatcher, because all callbacks are realized in background thread, away from main UI thread of WP7 application.

A complete list of featured methods (with comments) can be found here.