I must implement an asynchronous communication between client and server, I made a test application that does it through delegates (where the client subscribes to server’s instantiated delegate, that invokes every x seconds). Server and client are running on the same solution, and now I want to put the server on a VM and keep the communication. Is it doable through Delegates? If so, how?
Delegate:
public delegate void ClientStartedEventHandler(String s);
Client:
private void OnStartClick(object sender, EventArgs e)
{
Server.ClientStarted += ClientStarted;
Server.start();
}
private void ClientStarted(String s)
{
MessageBox.Show(s);
}
Server:
public static class Server
{
public static event ClientStartedEventHandler ClientStarted;
public static void start()
{
Timer myTimer = new System.Timers.Timer();
myTimer.Elapsed += new ElapsedEventHandler(exe);
myTimer.Interval = 2000;
myTimer.Enabled = true;
}
private static void exe(object source, ElapsedEventArgs e)
{
String strNow = DateTime.Now.ToString();
if (ClientStarted != null)
{
ClientStarted.Invoke(strNow);
}
}
}