예제 #1
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please specify your name");
                return;
            }
            // Instantiate a new Space repository.
            SpaceRepository repository = new SpaceRepository();

            // Add a gate, such that we can connect to it.
            repository.AddGate("tcp://127.0.0.1:123?CONN");

            // Add a new Fifo based space.
            repository.AddSpace("dtu", new SequentialSpace());

            // Insert a tuple with a message.
            repository.Put("dtu", "Hello student!");

            // Instantiate a remotespace (a networked space) thereby connecting to the spacerepository.
            ISpace remotespace = new RemoteSpace("tcp://127.0.0.1:123/dtu?CONN");

            // Instantiate a new agent, assign the tuple space and start it.
            AgentBase student = new Student(args[0], remotespace);

            student.Start();

            // Wait and retrieve the message from the agent.
            ITuple tuple = repository.Get("dtu", typeof(string), typeof(string));

            // Print the contents to the console.
            Console.WriteLine(string.Format("{0}, you are attending course {1}", tuple[0], tuple[1]));
            Console.Read();
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                // Instantiate a new space repository, and add two seperate gates.
                SpaceRepository repository = new SpaceRepository();
                repository.AddGate("tcp://127.0.0.1:123?KEEP");
                repository.AddGate("tcp://127.0.0.1:124?KEEP");

                // Create a new fifo based space, and insert the ping.
                repository.AddSpace("pingpong", new SequentialSpace());
                repository.Put("pingpong", "ping", 0);

                // Create two seperate remotespaces and agents.
                // The agents use their own private remotespace.
                RemoteSpace remotespace1 = new RemoteSpace("tcp://127.0.0.1:123/pingpong?KEEP");
                PingPong    a1           = new PingPong("ping", "pong", remotespace1);

                RemoteSpace remotespace2 = new RemoteSpace("tcp://127.0.0.1:124/pingpong?KEEP");
                PingPong    a2           = new PingPong("pong", "ping", remotespace2);

                // Start the agents
                a1.Start();
                a2.Start();
                Console.Read();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            string serverUrl = "tcp://" + ConnectionInfo.SERVER_ADDRESS + "/space?KEEP";

            Console.WriteLine($"Launching server at '{serverUrl}'");

            SpaceRepository repository = new SpaceRepository();

            repository.AddGate(serverUrl);
            SequentialSpace space = new SequentialSpace();

            repository.AddSpace(ConnectionInfo.SPACE_NAME, space);

            Connection.Space      = space;
            Connection.repository = repository;

            PlayerController newUserProtocol = new PlayerController();
            Thread           newUserThread   = new Thread(new ThreadStart(newUserProtocol.RunProtocol));

            newUserThread.Start();

            LobbyController lobbyController = new LobbyController(repository);

            lobbyController.Start();

            Console.WriteLine("Server started");
        }
예제 #4
0
        static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                if (args[0] == "producer")
                {
                    // Create a new space repository, and add a new gate to it.
                    // The gate is using CONN, meaning the connection is NOT persistent.
                    SpaceRepository repository = new SpaceRepository();
                    repository.AddGate("tcp://127.0.0.1:123?CONN");

                    // Add a new fifo based space
                    repository.AddSpace("fridge", new SequentialSpace());

                    // Create a new agent, and let the agent use the local tuple space instead of a networked remotespace.
                    AgentBase alice = new Producer("Alice", repository.GetSpace("fridge"));
                    alice.Start();
                    return;
                }
                else if (args[0] == "consumer")
                {
                    // The consumers use a remote space to access the space repository.
                    ISpace           remotespace = new RemoteSpace("tcp://127.0.0.1:123/fridge?CONN");
                    List <AgentBase> agents      = new List <AgentBase>();
                    agents.Add(new FoodConsumer("Bob", remotespace));
                    agents.Add(new FoodConsumer("Charlie", remotespace));
                    agents.Add(new DrugConsumer("Dave", remotespace));
                    agents.ForEach(a => a.Start());
                    Console.Read();
                    return;
                }
            }
            Console.WriteLine("Please specify [producer|consumer]");
            Console.Read();
        }
예제 #5
0
        static void Main(string[] args)
        {
            SpaceRepository repository = new SpaceRepository();
            string          ip         = null;
            string          port       = null;

            if (args.Length == 1)
            {
                ip   = args[0];
                port = "8989";
                repository.AddGate($"tcp://{ip}:8989?KEEP");
            }

            else if (args.Length == 2)
            {
                ip   = args[0];
                port = args[1];
                repository.AddGate($"tcp://{ip}:{port}?KEEP");
            }
            else
            {
                Console.WriteLine("Nenhum IP ou porta foi dado!");
                Console.WriteLine("Configuração default será usada!");
                ip   = "127.0.0.1";
                port = "8989";
                repository.AddGate("tcp://127.0.0.1:8989?KEEP");
            }

            repository.AddSpace("chat", new SequentialSpace());

            Servidor s = new Servidor(ip, port, repository);



            // string ip = null;
            // string port = null;
            // if(args.Length == 1){
            //     ip = args[0];
            //     port = "8989";
            // }
            // else if(args.Length == 2){
            //     ip = args[0];
            //     port = args[1];
            // }
            // else{
            //     ip = "127.0.0.1";
            //     port = "8989";
            // }
            // Servidor s = new Servidor(ip, port);

            // // Console.ReadKey();
            // while(true){Thread.Sleep(100);}

            Console.Read();
        }
예제 #6
0
 public SlideHostFacade(SpaceRepository repo, string identifier, ISlideShow slideShower)
 {
     _repo           = repo;
     SlideShower     = slideShower;
     _identifier     = identifier;
     _exposedSpace   = new SequentialSpace();
     _concealedSpace = new SequentialSpace();
     _repo.AddSpace("hub", _exposedSpace);
     Hub.Running        = true;
     SlideShower.IsHost = true;
 }
예제 #7
0
        static void Main(string[] args)
        {
            if (args.Length > 1)
            {
                if (args[0] == "table")
                {
                    // Instantiate a new space repository and add a gate to it.
                    SpaceRepository repository = new SpaceRepository();
                    repository.AddGate("tcp://" + args[1] + ":31415?KEEP");
                    repository.AddGate("tcp://" + args[1] + ":31416?KEEP");
                    repository.AddGate("tcp://" + args[1] + ":31417?KEEP");
                    repository.AddGate("tcp://" + args[1] + ":31418?KEEP");
                    repository.AddGate("tcp://" + args[1] + ":31419?KEEP");

                    // Add a new Fifo based space to the repository.
                    repository.AddSpace("DiningTable", new SequentialSpace());

                    // Insert the forks that the philosophers must share.
                    repository.Put("DiningTable", "FORK", 1);
                    repository.Put("DiningTable", "FORK", 2);
                    repository.Put("DiningTable", "FORK", 3);
                    repository.Put("DiningTable", "FORK", 4);
                    repository.Put("DiningTable", "FORK", 5);
                    return;
                }
                else if (args[0] == "philosopher")
                {
                    Console.WriteLine("connecting " + args[1]);

                    // Instantiate a new remote space, thereby allowing a persistant networked connection to the repository.
                    ISpace remotespace1 = new RemoteSpace("tcp://" + args[1] + ":31415/DiningTable?KEEP");
                    ISpace remotespace2 = new RemoteSpace("tcp://" + args[1] + ":31416/DiningTable?KEEP");
                    ISpace remotespace3 = new RemoteSpace("tcp://" + args[1] + ":31417/DiningTable?KEEP");
                    ISpace remotespace4 = new RemoteSpace("tcp://" + args[1] + ":31418/DiningTable?KEEP");
                    ISpace remotespace5 = new RemoteSpace("tcp://" + args[1] + ":31419/DiningTable?KEEP");

                    // Instantiate the philosopher agents and let them use the same connection to access the repository.
                    List <AgentBase> agents = new List <AgentBase>();
                    agents.Add(new Philosopher("Alice", 1, 5, remotespace1));
                    agents.Add(new Philosopher("Charlie", 2, 5, remotespace2));
                    agents.Add(new Philosopher("Bob", 3, 5, remotespace3));
                    agents.Add(new Philosopher("Dave", 4, 5, remotespace4));
                    agents.Add(new Philosopher("Homer", 5, 5, remotespace5));

                    // Let the philosophers eat.
                    agents.ForEach(a => a.Start());
                    Console.Read();
                    return;
                }
            }
            Console.WriteLine("Please specify [table|philosopher] and IP address to use");
            Console.Read();
        }
예제 #8
0
        private void AddGameLobby()
        {
            space = new SequentialSpace();
            ReservePlayersToSpace(space, MAX_NUM_SUBSCRIBERS);

            space.Put("winner-lock");

            repository.AddSpace(spaceID, space);

            //Initialize streeming components
            clientScores    = new ClientScores(space);
            streemComponent = new StreemComponents(space);
        }
예제 #9
0
        static void Main(string[] args)
        {
            SpaceRepository repository = new SpaceRepository();

            repository.AddGate("tcp://127.0.0.1:123?KEEP");
            repository.AddSpace("lifeforms", new SequentialSpace(new EntityFactory()));
            TerminalInfo.Initialize(80, 24);
            Game lifeforms = new Game(repository.GetSpace("lifeforms"));

            lifeforms.Run();
            Console.ReadKey();
            lifeforms.Stop();
        }
예제 #10
0
        public LoginServer()
        {
            var rsa    = new RSACryptoServiceProvider();
            var pubKey = rsa.ToXmlString(false);

            _privKey = rsa.ToXmlString(true);

            var ip = IpFetcher.GetLocalIpAdress();

            _loginServerSpaces.AddGate("tcp://" + ip + ":5001?CONN");
            _loginServerSpaces.AddSpace("loginAttempts", _loginAttempts);
            _loginServerSpaces.AddSpace("accountCreation", _accountCreation);
            _loginServerSpaces.AddSpace("getConferenceList", _getConferences);
            _loginAttempts.Put(pubKey);

            _getConferences.Put(new List <string>());

            Task.Factory.StartNew(GetAccountCreationService);
            Task.Factory.StartNew(GetLoginAttemptsService);
            Task.Factory.StartNew(GetConferenceListService);
            Task.Factory.StartNew(GetIpService);
            Task.Factory.StartNew(GetLogoutAttemptsService);
        }
 public void CreateSequentialSpaceWithSequentialSpaceNameGeneratorTest()
 {
     using (var spaceRepo = new SpaceRepository())
     {
         string uri       = "tcp://127.0.0.1:5005";
         string testName  = NameHashingTool.GenerateUniqueSequentialSpaceName("ThisNameDoesNotActuallyMatter");
         ISpace testSpace = new SequentialSpace();
         spaceRepo.AddSpace(testName, testSpace);
         spaceRepo.AddGate(uri + "?CONN");
         var testElement = "This string is a test";
         testSpace.Put(testElement);
         testSpace.Get(testElement);
         Debug.Assert(!testSpace.GetAll().Any());
         // putting and getting the element should leave us with an empty space
     }
 }
        public void CreateRemoteSpaceWithRemoteSpaceNameGeneratorTest()
        {
            using (var spaceRepo = new SpaceRepository())
            {
                string uri            = "tcp://127.0.0.1:5002";
                string testRemoteName = "ThisNameDoesNotActuallyMatter";
                string testSeqName    = NameHashingTool.GenerateUniqueSequentialSpaceName(testRemoteName);
                Console.WriteLine(testSeqName);
                var testSeqSpace = new SequentialSpace();
                spaceRepo.AddSpace(testSeqName, testSeqSpace);
                spaceRepo.AddGate(uri);

                var remoteHash = NameHashingTool.GenerateUniqueRemoteSpaceUri(uri, testRemoteName);
                Console.WriteLine(remoteHash);
                var testRemoteSpace = new RemoteSpace(remoteHash);
            }
        }
예제 #13
0
        // Create lobby (including tuple space), and send response
        // to player
        private void HandleCreationRequest(uint playerId, string playerName)
        {
            string lobbyId = GenerateLobbyId();

            string lobbyUrl = "tcp://" + ConnectionInfo.SERVER_ADDRESS + "/" + lobbyId + "?KEEP";

            var lobbySpace = new SequentialSpace();

            repository.AddSpace(lobbyId, lobbySpace);

            Lobby lobby = new Lobby(lobbySpace, lobbyId, playerId, playerName, lobbyUrl);

            lobbies.TryAdd(lobbyId, lobby);

            // Create lobby tuple
            Connection.Space.Put("existingLobby", lobbyId, playerName, lobbyUrl);
            lobby.Start();

            Console.WriteLine($"Lobby created: '{lobbyUrl}' (creator: {playerName})");

            // Returning space information to the global space so that users can connect to the space.
            Connection.Space.Put("lobbyCreationResponse", (int)playerId, playerName, lobbyUrl);
        }
예제 #14
0
        static void Main(string[] args)
        {
            // Instantiate a new Space repository.
            SpaceRepository repository = new SpaceRepository();

            // Add a gate, such that we can connect to it.
            repository.AddGate("tcp://127.0.0.1:9876?KEEP");

            // Add a new Fifo based space.
            repository.AddSpace("dtu", new SequentialSpace());

            Console.WriteLine("Starting");
            repository.Put("dtu", 0);

            // Instantiate a remotespace (a networked space) thereby connecting to the spacerepository.
            ISpace remotespace = new RemoteSpace("tcp://127.0.0.1:9876/dtu?KEEP");

            // Instantiate a new agent, assign the tuple space and start it.
            AgentBase userA = new User("A", remotespace);
            AgentBase userB = new User("B", remotespace);

            userA.Start();
            userB.Start();
        }
예제 #15
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Error: Wrong number of parameters");
                Console.WriteLine("Expected: [calc|imp1|imp2|click] [IP address] ([impressions] [clicked] [out])");
            }

            var address = args[1];

            if (args[0] == "calc")
            {
                if (args.Length < 5)
                {
                    Console.WriteLine("Error: Wrong number of parameters");
                    Console.WriteLine(args[0]);
                    Console.WriteLine("Expected for calculator: [calc] [IP address] [impressions] [clicked] [out]");
                    return;
                }

                var impressionFileName = args[2];
                var clickFileName      = args[3];
                var outFileName        = args[4];

                // Instantiate a new Space repository.
                SpaceRepository repository = new SpaceRepository();

                // Add a gate, such that we can connect to it.
                repository.AddGate("tcp://" + address + ":" + IMP_PORT1 + "?KEEP");
                repository.AddGate("tcp://" + address + ":" + IMP_PORT2 + "?KEEP");
                repository.AddGate("tcp://" + address + ":" + CLICK_PORT + "?KEEP");
                repository.AddGate("tcp://" + address + ":" + CALC_PORT + "?KEEP");

                // Add a new tree space.
                repository.AddSpace("tSpace", new TreeSpace());

                // Instantiate a remotespace (a networked space) thereby connecting to the spacerepository.
                ISpace remoteSpace = new RemoteSpace("tcp://" + address + ":" + CALC_PORT + "/tSpace?KEEP");

                var clickRateCalculator = new ClickRateCalculator(remoteSpace, clickFileName, impressionFileName, outFileName);
                clickRateCalculator.Start();
            }
            else if (args[0] == "imp1")
            {
                ISpace remoteSpace = new RemoteSpace("tcp://" + address + ":" + IMP_PORT1 + "/tSpace?KEEP");

                var impressionLogAgent = new ImpressionEntryParser("1", remoteSpace, Program.IMP_FILE);
                impressionLogAgent.Start();
            }
            else if (args[0] == "imp2")
            {
                ISpace remoteSpace = new RemoteSpace("tcp://" + address + ":" + IMP_PORT2 + "/tSpace?KEEP");

                var impressionLogAgent = new ImpressionEntryParser("2", remoteSpace, Program.IMP_FILE);
                impressionLogAgent.Start();
            }
            else if (args[0] == "click")
            {
                ISpace remoteSpace = new RemoteSpace("tcp://" + address + ":" + CLICK_PORT + "/tSpace?KEEP");

                var clickLogAgent = new ClickEntryParser("click", remoteSpace, Program.CLICK_FILE);
                clickLogAgent.Start();
            }
            else
            {
                Console.WriteLine("Please specify [calc|imp1|imp2|click]");
            }
        }