コード例 #1
0
        // Starts the server; Make sure to give the server a unique ID
        public bool Start(string brokerAddress, int brokerPort, string serverID)
        {
            // Create a new networking manager
            networkingManager = new NetworkingManager(attachedApplication);
            // Generate a new world
            attachedApplication.output.PrintLine("Generating new world...");
            world = new World.World(attachedApplication, new Random().Next());
            // Start the new world in a thread
            Thread worldThread = new Thread(world.Start);

            worldThread.Start();
            attachedApplication.output.PrintLine("Connecting to broker...");
            // Connect to the broker
            bool connectedToBroker = networkingManager.Connect(brokerAddress, brokerPort, serverID, 10);

            // If the connection was successful
            if (connectedToBroker)
            {
                attachedApplication.output.PrintLine("Connected!");
                // Setup the send and recieve topics
                recieveCommandsTopic = serverID + "/Recieve";
                networkingManager.Subscribe(recieveCommandsTopic);
                sendCommandsTopic = serverID + "/Send";
                // Add our OnRecieveCommand event to the networking manager so we can recieve messages
                networkingManager.MessageRecieved += OnRecieveCommand;
            }
            return(connectedToBroker);
        }
コード例 #2
0
        // Connects this client up to a server; Make sure to give the client a unique ID
        public bool Connect(string brokerAddress, int brokerPort, string newClientID, string serverID)
        {
            // Create a new networking manager
            networkingManager = new NetworkingManager(attachedApplication);
            // Connect to the broker
            bool connectedToBroker = networkingManager.Connect(brokerAddress, brokerPort, newClientID, 10);

            // If the connection was successful
            if (connectedToBroker)
            {
                clientID = newClientID;
                // Setup the send and recieve topics
                sendCommandsTopic          = serverID + "/Recieve";
                recieveCommandsTopic       = serverID + "/Send";
                directRecieveCommandsTopic = recieveCommandsTopic + "/" + newClientID;
                networkingManager.Subscribe(recieveCommandsTopic);
                networkingManager.Subscribe(directRecieveCommandsTopic);
                // Add our OnRecieveCommand event to the networking manager so we can recieve messages
                networkingManager.MessageRecieved += OnRecieveRPC;
            }
            return(connectedToBroker);
        }
コード例 #3
0
 // Initialize
 public Client(Application application)
 {
     attachedApplication = application;
     networkingManager   = new NetworkingManager(application);
 }