I have two independent application, how to transfer data?

I have two independent application:-

Application A:- Currently under development and hence use VS debug operation, sometime I quit the test via VS rather than exiting the application which close particular session (this is rather a bad habit, I admit) with the equipment at the network. This equipment is left with open session and will crash if the application A run again and attempt to open the session. I'm using Tektronix VISA protocol to open and close session to the network and comminicate with equipment remotely.

Application B:- This is fully independent program that sit on background and recieves the session information from the Application A, it also recieves watchdog signal (every 1-10 second say) from the Application A so that it know it running. When Application A discontinue without proper exit, the watchdog signal to Application B discontinue and hence the timeout event, which close the session on behalf of the Application A.

What is the best way to send string, int data to to the Application B and send watchdog signal to Application B?.

One possible solution is to transfer file into HD and update them with timestamp and session details, I looking for smarter way to transfer data real time.

Any suggestion how, please send working example if possible.

riscyAsked:
Who is Participating?
 
solublefishConnect With a Mentor Commented:
Use network calls. The socket libraries are robust and reliable, and they'll let you put the watchdog on another machine, potentially handle multiple clients, etc.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemNetSocketsSocketClassTopic.asp

You can do something really simple with UDP. The code below should be a decent starting point. It's only a little bit modified from MSFT's sample code.



//server side----------------------------
      [STAThread]
            static void Main()
            {
                  while(true)
                  {
                        ReceiveFrom(12345);
                        Application.DoEvents();
                  }
            }

            public static void ReceiveFrom(int portNum)
            {
                  //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetsocketssocketclassreceivefromtopic.asp
                  IPHostEntry hostEntry = Dns.Resolve(Dns.GetHostName());
                  IPEndPoint endPoint = new IPEndPoint(hostEntry.AddressList[0], portNum);

                  Socket s = new Socket(endPoint.Address.AddressFamily,
                        SocketType.Dgram,
                        ProtocolType.Udp);
       
                  // Creates an IpEndPoint to capture the identity of the sending host.
                  IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
                  EndPoint senderRemote = (EndPoint)sender;
   
                  // Binding is required with ReceiveFrom calls.
                  s.Bind(endPoint);
                  byte[] msg = new Byte[256];
                  Console.WriteLine ("Waiting to receive datagrams from client...");
                  // This call blocks.  
                  s.ReceiveFrom(msg, 0, msg.Length, SocketFlags.None, ref senderRemote);
                  s.Close();
                  Console.WriteLine(System.Text.Encoding.ASCII.GetString(msg));
            }
//----------------------------------------------------

//client side--------------------------------------
public static void SendTo(int portNum, string str)
            {
                  //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetsocketssocketclasssendtotopic.asp
                  IPHostEntry hostEntry = Dns.Resolve(Dns.GetHostName());
                  IPEndPoint endPoint = new IPEndPoint(hostEntry.AddressList[0], portNum);

                  Socket s = new Socket(endPoint.Address.AddressFamily,
                        SocketType.Dgram,
                        ProtocolType.Udp);
 
                  byte[] msg = System.Text.Encoding.ASCII.GetBytes(str);
                  Console.WriteLine("Sending data: " + str);
                  // This call blocks.
                  s.SendTo(msg, 0, msg.Length, SocketFlags.None, endPoint);
                  s.Close();
            }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.