Exemplo n.º 1
0
        private void AskForJobs()
        {
            JobAction receivedAction = null;

            Sender.Connect(RemoteEp);

            do
            {
                var bytes = new byte[100000];
                try
                {
                    Sender.Receive(bytes);
                    receivedAction = (JobAction)SocketHelper.Deserialize(bytes);

                    if (!receivedAction.NoJobsLeft)
                    {
                        Console.WriteLine("I got a job");
                        receivedAction.Run();

                        Sender.Send(SocketHelper.Serialize(receivedAction));
                    }
                }
                catch (SocketException e)
                {
                    Console.WriteLine(e);
                    Sender.Shutdown(SocketShutdown.Both);
                    Sender.Close();
                }
            } while (receivedAction != null && !receivedAction.NoJobsLeft);
        }
Exemplo n.º 2
0
        private void SendJob(Socket worker, byte[] bytes)
        {
            worker.Send(SocketHelper.Serialize(Tracker.GetJob()));
            Console.WriteLine($"Job sent to woker: {Tracker.Jobs.Count} jobs left.");

            worker.Receive(bytes);

            var jobAction = (JobAction)SocketHelper.Deserialize(bytes);

            Tracker.AddResult(jobAction);
        }