[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I have two independent application, how to transfer data?

Posted on 2005-04-19
4
Medium Priority
?
228 Views
Last Modified: 2010-04-16
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.

0
Comment
Question by:riscy
1 Comment
 
LVL 3

Accepted Solution

by:
solublefish earned 2000 total points
ID: 13820033
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question