private static void WriteMessages() { while (Connected && !waitingForResponse) { try { Console.WriteLine("Enter Username:"******"Enter Password"); string userpwsrd = Console.ReadLine(); Json_Obj MessageRequest = new Json_Obj() { UserID = userid, PswdHash = userpwsrd, RequestType = Json_Obj.RequestTypes.Get_User }; string messageData = JsonConvert.SerializeObject(MessageRequest); // Get bytes from data (string) byte[] msg = Encoding.ASCII.GetBytes(messageData); //sends message to client networkStream.Write(msg, 0, msg.Length); waitingForResponse = true; } catch (Exception e) { Console.WriteLine("_________________________________________________________________________________"); Console.WriteLine(e.Message); Console.WriteLine("_________________________________________________________________________________"); } } }
private static void ListenForMessages() { try { while (Connected) { int i = 0; Byte[] bytes = new Byte[256]; String data = null; while ((i = networkStream.Read(bytes, 0, bytes.Length)) != 0) { data = Encoding.ASCII.GetString(bytes, 0, i); Console.WriteLine(data); try { Json_Obj json_Obj = JsonConvert.DeserializeObject <Json_Obj>(data); switch (json_Obj.RequestType) { case Json_Obj.RequestTypes.Get_User: break; case Json_Obj.RequestTypes.Create_User: break; case Json_Obj.RequestTypes.Update_User: break; case Json_Obj.RequestTypes.Delete_User: break; case Json_Obj.RequestTypes.Response: Console.WriteLine($"Message Type: {json_Obj.RequestType.ToString()} \nMessage: {json_Obj.Message}\nStatus: {json_Obj.Status.ToString()}"); waitingForResponse = false; break; case Json_Obj.RequestTypes.Error: Console.WriteLine($"Message Type: {json_Obj.RequestType.ToString()} \nError: {json_Obj.Message}"); break; default: break; } } catch (Exception) { } } } } catch (Exception e) { Console.WriteLine("_________________________________________________________________________________"); Console.WriteLine(e.Message); Console.WriteLine("_________________________________________________________________________________"); } }
public Json_Val ToJsonVal() { Json_Obj obj = new Json_Obj(); obj.Add(new Json_Prop("name", this.Name.ToString())); //TODO: obj.Add(new Json_Prop("finger", (int)this.Finger));//sprite obj.Add(new Json_Prop("masu", (int)this.Masu.MasuNumber)); if (null != this.ResultKioku) { obj.Add(new Json_Prop("log", this.ResultKioku.ToJsonVal())); } return(obj); }
public static Json_Val ToJsonVal(IMoveHalf light) { Json_Obj obj = new Json_Obj(); RO_Star koma = Util_Starlightable.AsKoma(light.Now); // プレイヤーサイド obj.Add(new Json_Prop("pside", Conv_Playerside.ToSankaku(koma.Pside)));// ▲△ // マス obj.Add(new Json_Prop("masu", Conv_SyElement.ToMasuNumber(koma.Masu)));// ▲△ // 駒の種類。歩、香、桂…。 obj.Add(new Json_Prop("syurui", Conv_Komasyurui.ToStr_Ichimoji(Util_Komahaiyaku184.Syurui(koma.Haiyaku))));// ▲△ return(obj); }
public Json_Val ToJsonVal() { Json_Obj obj = new Json_Obj(); obj.Add(new Json_Prop("sippai", this.Sippai)); obj.Add(new Json_Prop("susunda", this.Susunda)); obj.Add(new Json_Prop("seiko", this.Seiko)); if (null != this.StartingSfenstringForKioku) { // 長いログになるので、後ろに回しました。 obj.Add(new Json_Prop("start_node2", this.StartingSfenstringForKioku)); //obj.Add(new Json_Prop("start_node", node.ToJsonVal())); } return(obj); }