//Sends dictionary accross network stream public void send_info(Object source, System.Timers.ElapsedEventArgs e) { try{ List <string> valuesDic = new List <string> (); g.Query(1, 2, new EOLMarker(), valuesDic); Byte[] r = Encoding.UTF8.GetBytes(valuesDic [0]); Byte[] resp = encode(r); strm.Write(resp, 0, resp.Length); } catch (Exception err) { //Fail Loudly Console.WriteLine(err); } }
public static void Main(string[] args) { //Set up vsync dictionary and handlers Dictionary <string, string> valueStore = new Dictionary <string, string> (); valueStore ["user1"] = "0,1,0,1,1,2"; valueStore ["user2"] = "1,1,1,1,1,1"; const int UPDATE = 0; const int LOOKUP = 1; const int REFRESH = 2; const int REMOVE = 3; Console.WriteLine("Hello World!"); VsyncSystem.Start(); Console.WriteLine("VSYNC STARTED"); Vsync.Group g = new Vsync.Group("dataHolder"); g.ViewHandlers += (ViewHandler) delegate(View v) { VsyncSystem.WriteLine("New View: " + v); Console.Title = "View " + v.viewid + ", my rank=" + v.GetMyRank(); }; g.Handlers[UPDATE] += (Action <string, string>) delegate(string username, string val) { VsyncSystem.WriteLine("IN UPDATE"); valueStore[username] = val; }; g.Handlers[LOOKUP] += (Action <string>) delegate(string s) { VsyncSystem.WriteLine("IN LOOKUP"); g.Reply(valueStore[s]); }; g.Handlers [REFRESH] += (Action) delegate() { string reply = Extensions.FromDictionaryToJson(valueStore); g.Reply(reply); }; g.Handlers [REMOVE] += (Action <string>) delegate(string s) { VsyncSystem.WriteLine("DELETING USER " + s); valueStore.Remove(s); }; /*g.MakeChkpt += (Vsync.ChkptMaker)delegate(View nv) { * g.SendChkpt(valueStore); * g.EndOfChkpt(); * }; * g.LoadChkpt += (loadVSchkpt)delegate(Dictionary<string, position> vs) { * valueStore = vs; * }; */ g.Join(); //Quick visual check to make sure initialization goes smoothely //UNNECESSARY -> TAKE OUT LATER List <string> valuesDic = new List <string> (); g.Query(1, REFRESH, new EOLMarker(), valuesDic); Console.WriteLine(valuesDic [0]); //Set up TCP Listener TcpListener server = new TcpListener(7569); server.Start(); Console.WriteLine("Server has started on 127.0.0.1:7569.{0}Waiting for a connection...", Environment.NewLine); //Listen for connections while (true) { TcpClient client = server.AcceptTcpClient(); handler h = new handler(client, g); //Spin off new thread to handle clients as they arrive Thread handler = new Thread(new ThreadStart(h.handle)); handler.Start(); Console.WriteLine("A Client Connected!"); } }