private void MainForm_Load(object sender, EventArgs e) { int_token = 0; /*AuthForm = new AuthentificationForm(); * RegForm = new RegistartionForm(); * SmileForm = new Smiles(); * PForm = new Port();*/ TextBox_username = fieldUsername; try { config = IMainFunction.FromJsonFile <Config>("config.json"); } catch { config = new Config() { _Width = 622, //622 _Height = 441, //441 _Update_rate = 1000, //1000 _Port = "5000" //5000 }; IMainFunction.ToJsonFile("config.json", config); } Width = config._Width; Height = config._Height; updateLoop.Interval = config._Update_rate; }
private void button1_Click(object sender, EventArgs e) { config = IMainFunction.FromJsonFile <Config>("config.json"); config._Port = textBox1.Text; IMainFunction.ToJsonFile("config.json", config); MessageBox.Show("Вы поменяли порт.", "Изменение порта", MessageBoxButtons.OK, MessageBoxIcon.Information); mForm.Show(); this.Visible = false; Application.Restart(); }
private void AuthentificationForm_Load(object sender, EventArgs e) { try { config = IMainFunction.FromJsonFile <Config>("config.json"); } catch { config = new Config() { _Port = "5000"//5000 }; IMainFunction.ToJsonFile("config.json", config); } }
// Отправляет сообщение на сервер public void SendMessage(Message msg) { config = IMainFunction.FromJsonFile <Config>("config.json"); WebRequest req = WebRequest.Create("http://localhost:" + config._Port + "/api/chat"); //WebRequest req = WebRequest.Create("http://localhost:5000/api/chat"); req.Method = "POST"; string postData = JsonConvert.SerializeObject(msg); //byte[] bytes = Encoding.UTF8.GetBytes(postData); req.ContentType = "application/json"; //req.ContentLength = bytes.Length; StreamWriter reqStream = new StreamWriter(req.GetRequestStream()); reqStream.Write(postData); reqStream.Close(); req.GetResponse(); }
// Получает сообщение с сервера Message GetMessage(int id) { config = IMainFunction.FromJsonFile <Config>("config.json"); try { WebRequest req = WebRequest.Create("http://localhost:" + config._Port + $"/api/chat/{id}"); //WebRequest req = WebRequest.Create($"http://localhost:5000/api/chat/{id}"); WebResponse resp = req.GetResponse(); string smsg = new StreamReader(resp.GetResponseStream()).ReadToEnd(); if (smsg == "Not found") { return(null); } return(JsonConvert.DeserializeObject <Message>(smsg)); } catch { return(null); } }