void listenclient(TcpClient client) { StringBuilder builder; NetworkStream stream = client.GetStream(); int i = 0; try { while (true) { builder = new StringBuilder(); int bytes = 0; byte[] data = new byte[1000000]; i = 1; do { bytes = stream.Read(data, 0, data.Length); builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); }while (client.Available > 0); string newstate = ExtractLastMessage(data, bytes); GameState state = JsonConvert.DeserializeObject <GameState>(newstate); owner.Invoke(new Del((s) => owner.LoadFromState(s)), state); } } catch (Exception ex) { owner.Invoke(new DelNull(() => owner.ResetGame())); client.Close(); } }
public void moveGhost(int roundID, string monster_arg) { string[] monst_tok = monster_arg.Split(':'); form.Invoke(new delmoveGhost(form.updateGhostsMove), new object[] { Int32.Parse(monst_tok[0]), Int32.Parse(monst_tok[2]), Int32.Parse(monst_tok[4]), Int32.Parse(monst_tok[5]) }); }