static void Main(string[] args) { // Initialize platforms for various used SDKs GizmoSDK.GizmoBase.Platform.Initialize(); GizmoSDK.GizmoDistribution.Platform.Initialize(); // Create a manager. The manager controls it all DistManager manager = DistManager.GetManager(true); DistTransportType protocol = DistTransportType.MULTICAST; //string iface = "${wi-fi}"; //string iface = "10.132.0.5"; string iface = "127.0.0.1"; string adress = "234.5.6.19"; ushort server_port = 1122; ushort client_port = 2211; //string iface = null; // Start the manager with settting for transport protocols //manager.Start(DistRemoteChannel.CreateDefaultSessionChannel(true,protocol, iface), DistRemoteChannel.CreateDefaultServerChannel(true,protocol, iface)); manager.Start(DistRemoteChannel.CreateChannel(5000, protocol, adress, client_port, iface), DistRemoteChannel.CreateChannel(5000, protocol, adress, server_port, iface)); // Client set up. You are a client that sends and receives information DistClient client = new DistClient("PerfClient", manager); // We need to tell the client how to initialize client.Initialize(0, 0); // Now we can get a session. A kind of a meeting room that is used to exchange various "topics" DistSession session = client.GetSession("PerfSession", true, true); // Joint that session and subribe all events client.JoinSession(session); client.SubscribeEvents(session); // Subscribe All Events // Create a delegete client.OnEvent += Client_OnEvent; Console.WriteLine($"Press <RETURN> to start sending"); // Now loops around some simple program to get strings from console and distribute them as a message app while (true) { string result = Console.ReadLine(); if (result == "quit") { break; } // Create COUNT test events Timer timer = new Timer(); DistEvent [] e_arr = new DistEvent[COUNT]; for (int i = 0; i < COUNT; i++) { e_arr[i] = new DistEvent(); e_arr[i].SetAttributeValue("Cnt", i); // Set some additional data e.g. two vec3 e_arr[i].SetAttributeValue("vec1", new Vec3(1, 2, 3)); e_arr[i].SetAttributeValue("vec2", new Vec3(4, 5, 6)); } Console.WriteLine($"Created {COUNT} events in {timer.GetTime()} seconds -> Frequency: { timer.GetFrequency(COUNT)}"); // Send COUNT events timer = new Timer(); for ( int i = 0; i < COUNT; i++) { client.SendEvent(e_arr[i], session); } Console.WriteLine($"Sent {COUNT} events in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(COUNT)}"); } while (manager.HasPendingData()) { System.Threading.Thread.Sleep(10); } client.Uninitialize(true); // Some kind of graceful shutdown manager.Shutdown(); // GC and platform uninit is managed by the system automatically }
private static extern IntPtr DistCreateChannel(UInt32 reliableBufferSize, DistTransportType transportType, string address, UInt16 port, string interfaceAddress);
private static extern IntPtr DistCreateDefaultServerChannel(bool reliable, DistTransportType transportType, string interfaceAddress);
static public DistRemoteChannel CreateChannel(UInt32 reliableBufferSize = 5000, DistTransportType transportType = DistTransportType.MULTICAST, string address = DEFAULT_IP_ADDRESS, UInt16 port = DEFAULT_SESSION_PORT, string interfaceAddress = null) { return(new DistRemoteChannel(DistCreateChannel(reliableBufferSize, transportType, address, port, interfaceAddress))); }
static public DistRemoteChannel CreateDefaultServerChannel(bool reliable = true, DistTransportType transportType = DistTransportType.MULTICAST, string interfaceAddress = null) { return(new DistRemoteChannel(DistCreateDefaultServerChannel(reliable, transportType, interfaceAddress))); }
static void Main(string[] args) { // Initialize platforms for various used SDKs GizmoSDK.GizmoBase.Platform.Initialize(); GizmoSDK.GizmoDistribution.Platform.Initialize(); GizmoSDK.GizmoBase.Message.SetMessageLevel(MessageLevel.DEBUG); // Create a manager. The manager controls it all DistManager manager = DistManager.GetManager(true); DistTransportType protocol = DistTransportType.MULTICAST; //string iface = "127.0.0.1"; string iface = ""; // Start the manager with settting for transport protocols manager.Start(DistRemoteChannel.CreateDefaultSessionChannel(false, protocol, iface), DistRemoteChannel.CreateDefaultServerChannel(false, protocol, iface)); // Client set up. You are a client that sends and receives information DistClient client = new DistClient("PerfClient", manager); // We need to tell the client how to initialize client.Initialize(0, 0, true); // Now we can get a session. A kind of a meeting room that is used to exchange various "topics" DistSession session = client.GetSession("PerfSession", true, true); // Joint that session and subribe all events client.JoinSession(session); client.SubscribeObjects(session); // Subscribe All Objects // Create a delegete client.OnNewObject += Client_OnNewObject; client.OnNewAttributes += Client_OnNewAttributes; client.OnUpdateAttributes += Client_OnUpdateAttributes; Console.WriteLine($"Press <RETURN> to start sending"); // Now loops around some simple program to get strings from console and distribute them as a message app while (true) { string result = Console.ReadLine(); if (result == "quit") { break; } Timer timer = new Timer(); DistObject [] objects = new DistObject[OBJECTS]; for (int i = 0; i < OBJECTS; i++) { objects[i] = manager.GetObject($"Object {i}"); client.AddObject(objects[i], session); objects[i] = client.WaitForObject($"Object {i}", session); } Console.WriteLine($"Added {OBJECTS} objects in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(OBJECTS)}"); // make sure all objects are updated once DistTransaction transaction = new DistTransaction(); for (int j = 0; j < OBJECTS; j++) { transaction.NewTransaction(); transaction.SetAttributeValue("Test", 0.0); transaction.SetAttributeValue("id", Guid.NewGuid()); if (!client.UpdateObject(transaction, objects[j])) { Console.WriteLine("Boo"); } } System.Threading.Thread.Sleep(10); // Send COUNT updates on OBJECTS objects timer = new Timer(); for (int i = 0; i < COUNT; i++) { for (int j = 0; j < OBJECTS; j++) { transaction.NewTransaction(); transaction.SetAttributeValue("Test", timer.GetTime()); if (!client.UpdateObject(transaction, objects[j])) { Console.WriteLine("Failed to update object"); } } } Console.WriteLine($"Updated {OBJECTS} objects with {COUNT} updates in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(COUNT*OBJECTS)}"); } while (manager.HasPendingData()) { System.Threading.Thread.Sleep(10); } client.Uninitialize(true); // Some kind of graceful shutdown manager.Shutdown(); // GC and platform uninit is managed by the system automatically }