static void ReceiverInitWorkaround(string config) { string msg = Guid.NewGuid().ToString(); Console.WriteLine("Bug workaround - waiting for own answer."); CLIConfig cfg = LoadConfig(config + ".local"); ConfigManager cm = new ConfigManager(config); List <ReceiverClient> list = new List <ReceiverClient>(); Peer p = cm.Config.Peers.Single(x => x.PeerID == cm.Config.MyID); Console.WriteLine("Init receiver channel: " + p.ChannelID.ToString()); ReceiverClient client = new ReceiverClient(cm, p.ChannelID, cfg.ServerURL); client.MessageReceived = HandleReceivedInit; client.Connect(); SenderClient sclient = new SenderClient(cm, p.ChannelID, cfg.ServerURL); while (initReply.ToLower().Trim() != msg.ToLower().Trim()) { sclient.SendMessage(msg); Thread.Sleep(100); } Console.WriteLine("Got it... Good."); foreach (ReceiverClient r in list) { r.Disconnect(); } }
static CLIConfig LoadConfig(string config) { CLIConfig cfg; FileInfo cf = new FileInfo(config); if (!cf.Exists) { Console.WriteLine("Config file does not exist, creating default."); cfg = new CLIConfig() { ServerURL = "http://localhost:5000/" }; string jsonString; jsonString = JsonSerializer.Serialize(cfg); StreamWriter sw = cf.AppendText(); sw.WriteLine(jsonString); sw.Close(); } StreamReader sr = cf.OpenText(); string configtext = sr.ReadToEnd(); sr.Close(); cfg = JsonSerializer.Deserialize <CLIConfig>(configtext); return(cfg); }
static void Sender(string config) { CLIConfig cfg = LoadConfig(config + ".local"); ConfigManager cm = new ConfigManager(config); Console.WriteLine("Enter message:"); string msg = Console.ReadLine(); foreach (Peer p in cm.Config.Peers) { Console.WriteLine("Sender channel: " + p.ChannelID.ToString()); SenderClient client = new SenderClient(cm, p.ChannelID, cfg.ServerURL); client.CheckIfAvailable(); Console.WriteLine("Available: " + client.IsAvailable.ToString()); client.SendMessage(msg); } }
static void Receiver(string config) { CLIConfig cfg = LoadConfig(config + ".local"); ConfigManager cm = new ConfigManager(config); List <ReceiverClient> list = new List <ReceiverClient>(); foreach (Peer p in cm.Config.Peers) { Console.WriteLine("Receiver Channel: " + p.ChannelID.ToString()); ReceiverClient client = new ReceiverClient(cm, p.ChannelID, cfg.ServerURL); client.MessageReceived = HandleReceivedMessage; client.Connect(); } Console.WriteLine("Press enter to close"); Console.ReadLine(); //client.Disconnect(); foreach (ReceiverClient r in list) { r.Disconnect(); } }