private void Sendtime_Click(object sender, RoutedEventArgs e) { string catandper = MakeSure.EnsureQues(message, temp_minnum, temp_maxnum, wind_maxnum, humi_minnum, humi_maxnum, visible_minnum); TcpSend.SendTimeInform(catandper, iPAddress); sendtime.IsEnabled = false; }
public static void SendRedData(MainWindow mainWindow, Timer timer)//发送实时数据 { TcpClient tcpClient = new TcpClient(); try { tcpClient.NoDelay = true; tcpClient.Connect(IPAddress.Parse("127.0.0.1"), 9999); NetworkStream ns = tcpClient.GetStream(); if (MainWindow.i < MainWindow.datalist.Count && ns.CanWrite) { Byte[] bytSend = Encoding.UTF8.GetBytes(MainWindow.datalist[MainWindow.i].ToString()); ns.Write(bytSend, 0, bytSend.Length); ns.Flush(); if (!MakeSure.IsNormal(MainWindow.datalist[MainWindow.i], MainWindow.temp_minnum, MainWindow.temp_maxnum, MainWindow.wind_maxnum, MainWindow.humi_minnum, MainWindow.humi_maxnum, MainWindow.visible_minnum) && MainWindow.flag == 0)//第一次出现异常 { MainWindow.player.Load(); MainWindow.player.PlayLooping(); MainWindow.queshour = MainWindow.i; Application.Current.Dispatcher.Invoke(() => { mainWindow.status.Text = "异常"; mainWindow.status.Background = Brushes.Red; mainWindow.status.Foreground = Brushes.White; mainWindow.stopnoise.IsEnabled = true; mainWindow.extime.IsEnabled = true; mainWindow.ratio.IsEnabled = true; mainWindow.send.IsEnabled = true; }); MainWindow.message = MainWindow.datalist[MainWindow.i]; MainWindow.flag++; } MainWindow.i++; } else { ns.Close(); timer.Stop(); mainWindow.button.IsEnabled = true; return; } ns.Close(); } catch (Exception ee) { Console.WriteLine(ee.ToString()); MessageBox.Show("IP地址设置错误或接收端异常", "错误", MessageBoxButton.OK, MessageBoxImage.Warning); } finally { tcpClient.Close(); } }