Exemple #1
0
        //  This main thread simply starts several clients, and a server, and then
        //  waits for the server to finish.
        //
        static void Main(string[] args)
        {
            ZHelpers.VersionAssert(2, 1);

            List <Thread> clients = new List <Thread>(3);

            for (int clientNbr = 0; clientNbr < 3; clientNbr++)
            {
                clients.Add(new Thread(ClientTask));
                clients[clientNbr].Start();
            }

            Thread serverThread = new Thread(ServerTask);

            serverThread.Start();

            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            ZHelpers.VersionAssert(2, 1);
            List <Thread> workers = new List <Thread>(NBR_WORKERS);

            using (Context ctx = new Context(1)) {
                using (Socket client = ctx.Socket(SocketType.ROUTER)) {
                    client.Bind("tcp://*:5555");
                    for (int workerNbr = 0; workerNbr < NBR_WORKERS; workerNbr++)
                    {
                        workers.Add(new Thread(WorkerTask));
                        workers[workerNbr].Start();
                    }

                    for (int taskNbr = 0; taskNbr < NBR_WORKERS * 10; taskNbr++)
                    {
                        //  LRU worker is next waiting in queue
                        string address = client.Recv(Encoding.Unicode);
                        string empty   = client.Recv(Encoding.Unicode);
                        string ready   = client.Recv(Encoding.Unicode);

                        client.SendMore(address, Encoding.Unicode);
                        client.SendMore();
                        client.Send("This is the workload", Encoding.Unicode);
                    }

                    //  Now ask mamas to shut down and report their results
                    for (int taskNbr = 0; taskNbr < NBR_WORKERS; taskNbr++)
                    {
                        string address = client.Recv(Encoding.Unicode);
                        string empty   = client.Recv(Encoding.Unicode);
                        string ready   = client.Recv(Encoding.Unicode);

                        client.SendMore(address, Encoding.Unicode);
                        client.SendMore();
                        client.Send("END", Encoding.Unicode);
                    }
                    Console.ReadLine();
                }
            }
        }