Exemplo n.º 1
0
        public LetterDispatcher(HyperSocket hyperSocket, CancellationToken cancellationToken)
        {
            _hyperSocket = hyperSocket;
            _cancellationToken = cancellationToken;

            Task.Factory.StartNew(SendTask);
        }
Exemplo n.º 2
0
        public LetterDispatcher(HyperSocket hyperSocket, CancellationToken cancellationToken)
        {
            _hyperSocket       = hyperSocket;
            _cancellationToken = cancellationToken;

            Task.Factory.StartNew(SendTask);
        }
Exemplo n.º 3
0
Arquivo: Program.cs Projeto: riax/Clr
        private static void Main(string[] arg)
        {
            var options = new SocketOptions();
            options.ShutdownGrace = TimeSpan.FromSeconds(5);
            var unicastSocket = new HyperSocket(options);

            var stopwatch = new Stopwatch();

            int sent = 0;
            unicastSocket.Sent += (socket, letter) => {
                                      lock(SyncRoot) {
                                          sent++;
                                          if(sent%1000 == 0)
                                              Console.WriteLine("->" + sent);
                                      }
                                  };

            unicastSocket.Disconnecting += (socket, args) => Console.WriteLine("DISCONNECTING" + args.Binding + " " + args.Reason);
            unicastSocket.Disconnected += (socket, args) => Console.WriteLine("DISCONNECTED " + args.Binding + " " + args.Reason);
            unicastSocket.Connected += (socket, args) => Console.WriteLine("CONNECTED " + args.Binding);

            int received = 0;
            unicastSocket.Received += (socket, letter) => {
                                          lock(unicastSocket) {
                                              if(received == 0)
                                                  stopwatch.Restart();
                                              received++;

                                              if(received%20000 == 0)
                                                  Console.WriteLine("<-" + received);
                                              if(received%100000 == 0) {
                                                  Console.WriteLine("Received: " + received + " in " + stopwatch.ElapsedMilliseconds + " ms" + ". " + (received/stopwatch.ElapsedMilliseconds) + " letter/millisecond");
                                                  received = 0;
                                              }
                                          }
                                      };

            int port = int.Parse(arg[0]);
            unicastSocket.Bind(IPAddress.Any, port);

            string line;
            while((line = Console.ReadLine()) != null) {
                if(line == "exit")
                    break;

                if(line == "k") {
                    unicastSocket.Dispose();
                    Console.WriteLine("KILLED SOCKET");
                } else
                    for(int m = 0; m < 1000; m++)
                        unicastSocket.Send(new Letter {Type = LetterType.User, Options = LetterOptions.Multicast, Parts = new[] {new[] {(byte) 'A'}}});
            }

            unicastSocket.Dispose();

            Thread.Sleep(500);
        }
Exemplo n.º 4
0
Arquivo: Program.cs Projeto: riax/Clr
 private static void SendXLetters(HyperSocket unicastSocket, int numberToSend)
 {
     for(int i = 0; i < numberToSend; i++)
         unicastSocket.Send(new Letter {Options = LetterOptions.Ack | LetterOptions.Requeue, Type = LetterType.User, Parts = new[] {Encoding.Unicode.GetBytes("Hej " + i)}});
 }
Exemplo n.º 5
0
Arquivo: Program.cs Projeto: riax/Clr
        private static void Main()
        {
            var socketOptions = new SocketOptions();
            var unicastSocket = new HyperSocket(socketOptions);

            int sent = 0;

            unicastSocket.Sent += (socket, letter) => {
                                      lock(SyncRoot) {
                                          sent++;

                                          if(sent%20000 == 0)
                                              Console.WriteLine("SENT: " + sent);
                                      }
                                  };

            int received = 0;
            unicastSocket.Received += (socket, letter) => {
                                          received++;

                                          if(received%20000 == 0)
                                              Console.WriteLine("RECEIVED: " + received);
                                      };

            unicastSocket.Discarded += (letter, args) => Console.WriteLine("DISCARDED: " + args.Binding + " " + Encoding.Unicode.GetString(letter.Parts[0]));
            unicastSocket.Requeued += (letter, args) => Console.WriteLine("REQUEUED: " + letter);

            unicastSocket.Disconnecting += (socket, args) => Console.WriteLine("DISCONNECTING" + args.Binding + " " + args.Reason);
            unicastSocket.Disconnected += (socket, args) => {
                {
                    Console.WriteLine("DISCONNECTED " + args.Binding + " " + args.Reason);
                }
                                          };
            unicastSocket.Connected += (socket, args) => Console.WriteLine("CONNECTED " + args.Binding);
            int x = 0;
            unicastSocket.Initialized += (socket, args) => {
                                             //    unicastSocket.Dispose();
                                         };
            unicastSocket.Disposed += (socket, args) => unicastSocket.Connect(IPAddress.Parse("127.0.0.1"), 8001);

            unicastSocket.Connect(IPAddress.Parse("127.0.0.1"), 8001);
            //unicastSocket.Connect(IPAddress.Parse("127.0.0.1"), 8002);

            Console.WriteLine("Commands: ");
            Console.WriteLine("status\t\t- print number of sent and received letters");
            Console.WriteLine("any number\t\t- send a number of letters");
            Console.WriteLine("anything else\t- Send 1 000 000 letters");
            Console.WriteLine("exit\t\t- exit");

            string line;
            Console.Write("\n\nENTER COMMAND: ");
            while((line = Console.ReadLine()) != null) {
                if(line == "exit")
                    return;
                else if(line == "status")
                    WriteStatus(sent, received);
                else if(line == "reconnect") {
                    unicastSocket.Disconnect(IPAddress.Parse("127.0.0.1"), 8001);
                    unicastSocket.Connect(IPAddress.Parse("127.0.0.1"), 8001);
                } else if(line != "")
                    SendXLetters(unicastSocket, int.Parse(line));
                else
                    SendXLetters(unicastSocket, 1000000);
            }

            unicastSocket.Dispose();
        }