static void Main(string[] args) { IPublisher publisher = new Publisher(countOfChannels, countOfSubscribers); IDataMediator dataMediator = (IDataMediator) publisher; ISubscriber[] subscribers = new ISubscriber[countOfSubscribers]; for (int i = countOfSubscribers - 1; i >= 0; i--) { subscribers[i] = new Subscriber(publisher); } runSubscribe(subscribers, publisher); Thread.CurrentThread.Priority = ThreadPriority.Highest; for (int i = 0; i < 1000; i++) { Stopwatch latency = Stopwatch.StartNew(); int onLoadSubscribersCount = dataMediator.onLoad(randomBytes(10000), rnd.Next(countOfChannels)); latency.Stop(); Console.Write("latency is\t" + latency.Elapsed.Milliseconds + "\tfor\t" + onLoadSubscribersCount + "\tsubscribers"); Console.WriteLine(); } Console.WriteLine("thats all"); Console.ReadLine(); }
static void Main(string[] args) { parseParse(File.ReadAllText(@"C:\shuffly\Shuffly-Brain\papa.txt")); string channel = "/consolepublisher"; Console.WriteLine("Initializing..."); Client client = new Client(new ClientArgs { // replace with your domain key DomainKey = "035d9877-9eaf-45ef-936f-80087fb3a221", // replace with your domain name DomainName = "localhost", Synchronous = true }); Publisher publisher = new Publisher(new PublisherArgs { // replace with your domain key DomainKey = "035d9877-9eaf-45ef-936f-80087fb3a221", // replace with your domain name DomainName = "localhost", Synchronous = true }); client.Connect(new ConnectArgs { OnSuccess = (successArgs) => { Console.WriteLine("The client connected and has ID " + successArgs.ClientId + "."); }, OnFailure = (failureArgs) => { Console.WriteLine("The client could not connect... " + failureArgs.Exception.Message); }, OnStreamFailure = (streamFailureArgs) => { Console.WriteLine("The client could not stream... " + streamFailureArgs.Exception.Message); Console.WriteLine("The client " + (streamFailureArgs.WillReconnect ? "will" : "will not") + " automatically reconnect." + Environment.NewLine); } }); // client is configured as "synchronous", so this // won't execute until the connect method is complete if (client.State != ClientState.Connected) { Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); return; } Console.WriteLine("Connected"); client.Subscribe(new SubscribeArgs { Channel = channel, OnSuccess = (successArgs) => { Console.WriteLine("The client " + (successArgs.IsResubscribe ? "re-" : "") + "subscribed to " + channel + "."); }, OnFailure = (failureArgs) => { Console.WriteLine("The client could not subscribe to " + channel + "... " + failureArgs.Exception.Message); }, OnReceive = (receiveArgs) => { Payload payload = JSON.Deserialize<Payload>(receiveArgs.DataJson); Tuple<SpokeQuestion, string, GameBoard> vf = null; switch (payload.Type) { case SpokeMessageType.AskQuestion: return; case SpokeMessageType.JoinGame: playersInGame.Add(receiveArgs.PublishingClient.Id, payload.PlayerName); if (playersInGame.Count == 2) { vf = RunGame.StartGame("sevens", playersInGame); stackTrace = vf.Item2; } else return; break; case SpokeMessageType.AnswerQuestion: vf = RunGame.ResumeGame("sevens", stackTrace, payload.AnswerIndex, playersInGame); stackTrace = vf.Item2; Console.WriteLine(vf.Item1); break; default: throw new ArgumentOutOfRangeException(); } PublicationArgs fc; foreach (KeyValuePair<string, string> user in playersInGame) { fc = new PublicationArgs { Publication = new Publication { Channel = channel + "/gamedata/" + user.Value, DataJson = JSON.Serialize(vf.Item3) }, OnComplete = (completeArgs) => { if (completeArgs.Publication.Successful == true) { Console.WriteLine("The publisher published to " + channel + "."); } else { Console.WriteLine("The publisher could not publish to " + channel + "... " + completeArgs.Publication.Error); } }, OnException = (exceptionArgs) => { Console.WriteLine("The publisher threw an exception... " + exceptionArgs.Exception.Message); } }; publisher.Publish(fc); } SpokeQuestion q = vf.Item1; fc = new PublicationArgs { Publication = new Publication { Channel = channel + "/" + q.User, DataJson = JSON.Serialize(new Payload(q.Question, q.Answers)) }, OnComplete = (completeArgs) => { if (completeArgs.Publication.Successful == true) { Console.WriteLine("The publisher published to " + channel + "."); } else { Console.WriteLine("The publisher could not publish to " + channel + "... " + completeArgs.Publication.Error); } }, OnException = (exceptionArgs) => { Console.WriteLine("The publisher threw an exception... " + exceptionArgs.Exception.Message); } }; publisher.Publish(fc); // Console.WriteLine("The client received data... (text: " + payload.Text + ", time: " + payload.Time + ")"); } }); Console.WriteLine(); Console.WriteLine("Press Enter to publish text from the publisher. Press Escape to quit."); while (true) { ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(); if (consoleKeyInfo.Key == ConsoleKey.Escape) { return; } if (consoleKeyInfo.Key == ConsoleKey.Enter) { } } }