S
samiarja
Guest
I am trying to build a windows form application, where the user enter data, and then these data go to a structured JSON file. Every JSON string. Therefore. when the application is open, inside the Form1_Load operation I have tried to ping the IP address and change the label to either "In Range" or "Out of Range". but in order to have a reliable application I need to ping the ping the IP address periodically to ensure the the other device is within the range. The ultimate goal is to save files from remote server to a local server using SFTP.
Here what I was trying to do: but It only ping it once.
Ping p = new Ping();
PingReply r1;
PingReply r2;
PingReply r3;
PingReply r4;
string s1 = currentList[0].IPaddress;
string s2 = currentList[1].IPaddress;
string s3 = currentList[2].IPaddress;
string s4 = currentList[3].IPaddress;
//s = textBox2.Text;
textBox2.Text = s1;
r1 = p.Send(s1);
textBox3.Text = s2;
r2 = p.Send(s2);
textBox5.Text = s3;
r3 = p.Send(s3);
textBox11.Text = s4;
r4 = p.Send(s4);
if (r1.Status == IPStatus.Success)
{
label3.Text = "In Range";
}
else
{
label3.Text = "Out of Range";
}
if (r2.Status == IPStatus.Success)
{
label4.Text = "In Range";
}
else
{
label4.Text = "Out of Range";
}
if (r3.Status == IPStatus.Success)
{
label7.Text = "In Range";
}
else
{
label7.Text = "Out of Range";
}
if (r4.Status == IPStatus.Success)
{
label16.Text = "In Range";
}
else
{
label16.Text = "Out of Range";
}
Note that the IP addresses are extracted from a JSON file like below:
filePath = @"C:\Users\Sami\Desktop\Company";
string text = File.ReadAllText(filePath);
var currentList = JsonConvert.DeserializeObject<List<Datalogger>>(text);
//first data
textBox1.Text = currentList[0].Machinename;
textBox2.Text = currentList[0].IPaddress;
//second data
textBox4.Text = currentList[1].Machinename;
textBox3.Text = currentList[1].IPaddress;
Any thoughts?
Continue reading...
Here what I was trying to do: but It only ping it once.
Ping p = new Ping();
PingReply r1;
PingReply r2;
PingReply r3;
PingReply r4;
string s1 = currentList[0].IPaddress;
string s2 = currentList[1].IPaddress;
string s3 = currentList[2].IPaddress;
string s4 = currentList[3].IPaddress;
//s = textBox2.Text;
textBox2.Text = s1;
r1 = p.Send(s1);
textBox3.Text = s2;
r2 = p.Send(s2);
textBox5.Text = s3;
r3 = p.Send(s3);
textBox11.Text = s4;
r4 = p.Send(s4);
if (r1.Status == IPStatus.Success)
{
label3.Text = "In Range";
}
else
{
label3.Text = "Out of Range";
}
if (r2.Status == IPStatus.Success)
{
label4.Text = "In Range";
}
else
{
label4.Text = "Out of Range";
}
if (r3.Status == IPStatus.Success)
{
label7.Text = "In Range";
}
else
{
label7.Text = "Out of Range";
}
if (r4.Status == IPStatus.Success)
{
label16.Text = "In Range";
}
else
{
label16.Text = "Out of Range";
}
Note that the IP addresses are extracted from a JSON file like below:
filePath = @"C:\Users\Sami\Desktop\Company";
string text = File.ReadAllText(filePath);
var currentList = JsonConvert.DeserializeObject<List<Datalogger>>(text);
//first data
textBox1.Text = currentList[0].Machinename;
textBox2.Text = currentList[0].IPaddress;
//second data
textBox4.Text = currentList[1].Machinename;
textBox3.Text = currentList[1].IPaddress;
Any thoughts?
Continue reading...