This project contains examples for creating a TCP Server in .NET Core, a TCP Client in .NET Core, and also a TCP Client for Unity3d projects.
Examples listed below:
To Start a server:
Thread serverThread = new Thread(() => new Server("127.0.0.1" , 13000));
serverThread.Start();
To create a new client connection from Unity:
new Thread(() => {
Thread.CurrentThread.IsBackground = true;
ConnectClient(serverIPAddress, port, clientId, $"ClientId: {clientId} sending a message...");
}).Start();
To Dispatch events / messages to the main thread:
Dispatcher.Instance.Enqueue(() => Message(clientId, $"Sent: {message}"));
new Thread(() => {
Thread.CurrentThread.IsBackground = true;
ConnectClient("127.0.0.1", 13000, $"ClientId: {1} sending a message...");
}).Start();