Skip to content
forked from Jnnshschl/AnTCP

TCP Client (C#) and Server (C++) Library

License

Notifications You must be signed in to change notification settings

Gofrettin/AnTCP

 
 

Repository files navigation

AnTCP Client/Server

TCP Client (C#) and Server (C++) Library that i'll use in my projects, mainly the AmeisenBotX and its NavigationServer.

Usage Client

Create a new AnTcpClient with your IP and Port.

AnTcpClient client = new("127.0.0.1", 47110);

Call the Connect method.

client.Connect();

Call the send method to send data (example sends two integers, but any unmanaged variable can be used). 0x0 is the message type that needs to have a handler on the server side, more on that later.

(int, int) data = (new Random().Next(1, 11), new Random().Next(1, 11));
                    
AnTcpResponse response = client.Send((byte)0x0, data);

Convert the response to any unmanaged data type.

Console.WriteLine($">> Data: {response.As<int>()}");

Call the Disonnect method if your're done sending stuff.

client.Disconnect();

Usage Server

Create a new instance of the AnTcpServer with your IP and Port.

AnTcpServer server("127.0.0.1", "47110");

Create a callback function that will be called when the server received a message with type 0x0.

void AddCallback(ClientHandler* handler, const void* data, int size)
{
    // the function is going to add the two integers and retunrs its result
    int c = ((int*)data)[0] + ((int*)data)[1];
    handler->SendData((char)0x0, &c, 4);
}

Add the Callback to the server.

server.AddCallback((char)0x0, AddCallback);

Run the server.

server.Run();

About

TCP Client (C#) and Server (C++) Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 77.7%
  • C# 22.3%