private static void Main(string[] arg) { var options = new SocketOptions { ShutdownGrace = TimeSpan.FromMilliseconds(250) }; var hyperSocket = new HyperSocket(options); var stopwatch = new Stopwatch(); int sent = 0; hyperSocket.Sent += (letter, args) => { lock (SyncRoot) { sent++; if (sent % 1000 == 0) { Console.WriteLine("->" + sent); } } }; hyperSocket.Disconnecting += (socket, args) => Console.WriteLine("DISCONNECTING" + args.Binding + " " + args.Reason); hyperSocket.Disconnected += (socket, args) => Console.WriteLine("DISCONNECTED " + args.Binding + " " + args.Reason); hyperSocket.Connected += (socket, args) => Console.WriteLine("CONNECTED " + args.Binding); int received = 0; hyperSocket.Received += (letter, args) => { lock (SyncRoot) { 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]); hyperSocket.Bind(IPAddress.Any, port); string line; while ((line = Console.ReadLine()) != null) { if (line == "exit") { break; } if (line == "k") { hyperSocket.Dispose(); Console.WriteLine("KILLED SOCKET"); } else { for (int m = 0; m < 1000; m++) { hyperSocket.Send(new Letter { Type = LetterType.User, Options = LetterOptions.Multicast, Parts = new[] { new[] { (byte)'A' } } }); } } } hyperSocket.Dispose(); Thread.Sleep(500); }
private static void Main() { var socketOptions = new SocketOptions { ReconnectInterval = TimeSpan.FromMilliseconds(100) }; var hyperSocket = new HyperSocket(socketOptions); int sent = 0; int received = 0; hyperSocket.Sent += (socket, letter) => { lock (SyncRoot) { sent++; if (sent % 20000 == 0) { Console.WriteLine("SENT: " + sent); } } }; hyperSocket.Received += (socket, letter) => { received++; if (received % 20000 == 0) { Console.WriteLine("RECEIVED: " + received); } }; hyperSocket.Discarded += (letter, args) => Console.WriteLine("DISCARDED: " + args.Binding + " " + Encoding.Unicode.GetString(letter.Parts[0])); hyperSocket.Requeued += (letter, args) => Console.WriteLine("REQUEUED: " + letter); hyperSocket.Queuing += (letter, args) => { }; hyperSocket.Disconnecting += (socket, args) => Console.WriteLine("DISCONNECTING" + args.Binding + " " + args.Reason); hyperSocket.Disconnected += (socket, args) => Console.WriteLine("DISCONNECTED " + args.Binding + " " + args.Reason); hyperSocket.Connected += (socket, args) => Console.WriteLine("CONNECTED " + args.Binding); hyperSocket.Initialized += (socket, args) => Console.WriteLine("INITIALIZED"); hyperSocket.Disposed += (socket, args) => {}; hyperSocket.Connect(IPAddress.Parse("127.0.0.1"), 8001); hyperSocket.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") { hyperSocket.Disconnect(IPAddress.Parse("127.0.0.1"), 8001); hyperSocket.Connect(IPAddress.Parse("127.0.0.1"), 8001); } else if (line != "") { SendXLetters(hyperSocket, int.Parse(line)); } else { SendXLetters(hyperSocket, 1000000); } } hyperSocket.Dispose(); }