A simple method of posting JSON data using the window.fetch() method and receiving a response. In this scenario it was an empty response set but with a status indicator, such as an integer 204 indicating that the API accepted was posted.
A Tuple is great way to pass multiple values from a method, for example…
C#
private Tuple<string,int,bool>getStatus(){string element1 ="";string element2 ="";bool isActive =false;... // Some processing to populate the variablesreturnTuple.Create(element1,element2,isActive);{
The returned Tuple can be captured and its contents used as below;
C#
Tuple<string,string,bool> returnedData =getStatus();if(returnedData.Item3)// display message boxes if true{MessageBox.Show(returnedData.item1);MessageBox.Show(returnedData.item2);}
This very simple example shows how to return a Tuple containing three values, but the elements of a Tuple are not just limited to strings, int’s and booleans. The opportunities are there to get as creative as you need.
There is a limit, however, of up to 8 Tuples within a Tuple (an octuple). The Microsoft reference page for further reading is here: Tuple Class (System)
When storing passwords it’s important to ensure they’re not stored in plain text – this goes without saying these days, but there are still some systems that do this. Some hashing options such as md5 are easy to use, but is not recommended for use in any systems these days. The reason for this is that computing power has significantly improved since md5 was first introduced in 1991, which means brute force attacks are likely to succeed with ease.
The stock options when using PHP, however, keeps the hashing fairly simple, with the code below showing how to hash a password string.
An analyser kept loosing its connectivity to a server and it was not known why. One theory was the analyser (a Windows 10 device, heavily locked down to the point we couldn’t access the desktop) was performing some sort of power saving on the NIC after a period of inactivity.
Background: Once the analyser established a TCP/IP connection with the server, it kept the connection open, rather than an open->communicate->close process. This is seemingly a fairly fragile way to maintain communications especially when there are periods of non-communication (sometimes hours overnight) and the system didn’t perform any validation of an open connection before trying to send anything, which resulted in lots of error messages.
In order to rule out the power saving NIC issue I created a simple batch file script that pinged the analysers NIC every 60 seconds. This is a somewhat crude, yet simple way to keep the NIC from turning off as it shouldn’t have periods of idleness longer than 60 seconds.
As the script was going to be left running overnight, it was important to be able to monitor its progress, so additional lines were added to output the ping response to a text file that could be reviewed in the morning.
In the end, the issue was a firewall issue, but the script did help to rule out the analyser as the part of the equasion that was causing the problem.