Home

Awesome

SharpTox Build Status

This project aims to provide a simple library that wraps all of the functions found in the Tox library. Tox is a free (as in freedom) Skype replacement.

Feel free to contribute!

Things you'll need

Depending on how you compiled the core libraries, the names of those may differ from the defaults in SharpTox. Be sure to change the value of the const string dll in ToxFunctions.cs, ToxAvFunctions.cs, ToxDnsFunctions.cs and ToxEncryptionFunctions.cs accordingly if needed.

Compiling and Testing

Assuming you have the libraries mentioned above installed, it's time to compile (and test) SharpTox.

Windows

Or from the command line (Be sure to install NUnit and NuGet first):

git clone https://github.com/alexbakker/SharpTox
nuget restore
msbuild /p:Configuration:Debug
nunit-console-x86 SharpTox.Tests/bin/Debug/SharpTox.Tests.dll
Linux
git clone https://github.com/alexbakker/SharpTox
mono NuGet.exe restore
xbuild /p:Configuration="Debug POSIX"
nunit-console4 SharpTox.Tests/bin/Debug/SharpTox.Tests.dll

If you're having issues obtaining the NuGet packages, try executing: mozroots --import --sync

Looking for precompiled binaries? Check this.

Basic Usage

using System;
using SharpTox.Core;

class Program
{
    static Tox tox;

    static void Main(string[] args)
    {
        ToxOptions options = new ToxOptions(true, true);

        tox = new Tox(options);
        tox.OnFriendRequestReceived += tox_OnFriendRequestReceived;
        tox.OnFriendMessageReceived += tox_OnFriendMessageReceived;

        foreach (ToxNode node in Nodes)
            tox.Bootstrap(node);

        tox.Name = "SharpTox";
        tox.StatusMessage = "Testing SharpTox";

        tox.Start();

        string id = tox.Id.ToString();
        Console.WriteLine("ID: {0}", id);

        Console.ReadKey();
        tox.Dispose();
    }

    //check https://wiki.tox.im/Nodes for an up-to-date list of nodes
    static ToxNode[] Nodes = new ToxNode[]
    {
        new ToxNode("192.254.75.98", 33445, new ToxKey(ToxKeyType.Public, "951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F")),
        new ToxNode("144.76.60.215", 33445, new ToxKey(ToxKeyType.Public, "04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F"))
    };

    static void tox_OnFriendMessageReceived(object sender, ToxEventArgs.FriendMessageEventArgs e)
    {
        //get the name associated with the friendnumber
        string name = tox.GetFriendName(e.FriendNumber);

        //print the message to the console
        Console.WriteLine("<{0}> {1}", name, e.Message);
    }

    static void tox_OnFriendRequestReceived(object sender, ToxEventArgs.FriendRequestEventArgs e)
    {
        //automatically accept every friend request we receive
        tox.AddFriendNoRequest(e.PublicKey);
    }
}

Contact