Open bag7dad opened 11 months ago
Hello @medozeus, yes you can use the RUDP mode, and use unreliable in the same time, the RUDP implementation run two sockets in the same time, one in TCP and another in UDP. You can see the example in Reame RUDP section, observe the Enum "RudpMessageType.Reliable".
// create and start the server
var server = new KingServer(listenerType: NetworkListenerType.RUDP, port: 7171);
server.MessageReceivedHandler = OnMessageReceived;
//ASync execution
await server.StartAsync(); //You can pass a out var cancellationToken in parameter
//Sync execution
server.Start();
// implements the callback for MessageReceivedHandler
private void OnMessageReceived(IClient client, IKingBufferReader reader)
{
Console.WriteLine($"Received data from client {client.Id}, data length {reader.Length()}");
}
// send a message to all clients
using(var writer = KingBufferWriter.Create())
{
writer.Write("Test message!");
//You can use RudpMessageType.Reliable to send Reliable messages and RudpMessageType.Unreliable to send Unreliable messages
server.SendMessageToAll(writer, RudpMessageType.Reliable);
}
// stop the server when you don't need it anymore
server.Stop();
// create and connect the client
var client = new KingClient(listenerType: NetworkListenerType.RUDP);
client.MessageReceivedHandler = OnMessageReceived;
client.Connect("127.0.0.1", 7171);
// implements the callback for MessageReceivedHandler
private void OnMessageReceived(IKingBufferReader reader)
{
Console.WriteLine($"Received data from server, data length {reader.Length()}");
}
/// send a message to server
using(var writer = KingBufferWriter.Create()
{
writer.Write("Test message!");
//You can use RudpMessageType.Reliable to send Reliable messages and RudpMessageType.Unreliable to send Unreliable messages
client.SendMessage(writer, RudpMessageType.Reliable);
}
// disconnect from the server when we are done
client.Disconnect();
This method consumes significant resources, requiring two servers and two clients.
@medozeus Creating a socket instance consumes practically nothing of the machine, which makes something consume is to be traveling packages. And that you would already do being a connected or one, the amount of data you will travel would be the same in both occasions, only changes that part of them is in one connection and another part in another connection.
In Unity, most data syncing occurs unreliably, but sometimes there is a need to send reliable data to the same client within the same room. I think it's better to add options with the
send()
method, such assendOptions.reliable
andsendOptions.unreliable
. Also, issendOptions.reliable
sequenced?