Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Windows application communication
 

Windows application communication

I would like to implement a solution that allows a LAN applicationsto be aware ofother instancances of the same application and be able tocommunicate state changes that would require a refresh of global variables.

I am looking for some samples of how this has been achieved by others and any code/web/book references that have been used by the community in the past.

BNitz  Thursday, October 25, 2007 8:09 PM

One way to do it is to hold the shared data in a shared location (like a database or known network drive), and the application, using a Background Timer, will update this variables.

If you are looking for a way to notify about the changing of values ("push" rather than "pull), Try to create a "port" between the applications to notify about the changes. Here is an example for that:

1. Create a new project - "RemoteApplication".

1b. Add a refference to System.Runtime.Remoting

2. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

TcpServerChannel channel = new TcpServerChannel(8085);

ChannelServices.RegisterChannel(channel, false);

ObjRef SiteReference = RemotingServices.Marshal(this, "RemoteForm");

}

3. Change the Form.Text property to "This is the remote form".

4. Run the application (if the windows firewall ask something - click 'allow'\'don't block',etc.).

The form should appear.

5. Create a new project "ApplicationTalker".

6. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

if (ConnectToRemote())

this.Text = "I got '" + _remoteForm.Text + "' from the other app!";

}

private Form _remoteForm;

privatebool ConnectToRemote()

{

string Url = "tcp://localhost";

int Port = 8085;

string Name = "RemoteForm";

Url += ":" + Port + "/" + Name;

if (_remoteForm == null)

{

try

{

_remoteForm = (Form)Activator.GetObject(typeof(Form), Url);

}

catch (Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

return false;

}

}

return true;

}

7. Run the application - you should see the form text changed to "I got - 'This is the remote form' from the other app!".

8. This is it!

Eli Gazit  Thursday, October 25, 2007 10:36 PM

One way to do it is to hold the shared data in a shared location (like a database or known network drive), and the application, using a Background Timer, will update this variables.

If you are looking for a way to notify about the changing of values ("push" rather than "pull), Try to create a "port" between the applications to notify about the changes. Here is an example for that:

1. Create a new project - "RemoteApplication".

1b. Add a refference to System.Runtime.Remoting

2. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

TcpServerChannel channel = new TcpServerChannel(8085);

ChannelServices.RegisterChannel(channel, false);

ObjRef SiteReference = RemotingServices.Marshal(this, "RemoteForm");

}

3. Change the Form.Text property to "This is the remote form".

4. Run the application (if the windows firewall ask something - click 'allow'\'don't block',etc.).

The form should appear.

5. Create a new project "ApplicationTalker".

6. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

if (ConnectToRemote())

this.Text = "I got '" + _remoteForm.Text + "' from the other app!";

}

private Form _remoteForm;

privatebool ConnectToRemote()

{

string Url = "tcp://localhost";

int Port = 8085;

string Name = "RemoteForm";

Url += ":" + Port + "/" + Name;

if (_remoteForm == null)

{

try

{

_remoteForm = (Form)Activator.GetObject(typeof(Form), Url);

}

catch (Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

return false;

}

}

return true;

}

7. Run the application - you should see the form text changed to "I got - 'This is the remote form' from the other app!".

8. This is it!

Eli Gazit  Thursday, October 25, 2007 10:36 PM

You can use google to search for other answers

Custom Search

More Threads

• com port
• Remote Server Is Unreachable - New Install
• Terrarium 1.2 not showing any text on buttons?
• Deploying Windows Applications with Crystal Reports IN VS2005
• Source code, server and future
• "Thought for too long"?
• Terrarium Setup Help
• Can't see captions in Terrarium client
• Sounds interesting but looks dead
• Discussion Board