Network Application - basic question

  • Thread starter Thread starter CCLeasing
  • Start date Start date
C

CCLeasing

How do I communicate between different user instances of my windows
forms project?

Im trying to write a program that will run on a network of 15 pcs.

5 of the pc's will run the admin part of the program. and the rest of
the pc's will run the salesman part of the program.

Both forms (the admin form, and the salesman form) at this stage are
VERY simple as i'm just trying to learn the mechanics between basic
form communication accross the network.

The admin form has a couple of labels, a text box and a drop down box.
The text box allows the admin person to enter a leads name, and the
dropdown box allows the admin person to select which salesman they want
to send the lead to. Then when they press OK here is what i need to
happen...

Lets say from the dropdown box they selected the salesman called JOHN.

On Johns PC the app will popup a box alerting him that he has an
incoming lead.

It then pops up the salesman form, with the previously entered customer
name already populated and the time and date info also populated from
the data the admin person entered before they sent him the lead.

Can someone please explain how I achieve the above. I can create the
forms with no problems of course, but my question is asking about the
network side of things and how i actually get the forms to communicate
with each other / and find the right users form to activate.

Many Thanks.
 
Well I suppose there must be dozens of ways to do this; but I think the
most straight forward way to do it, just to get you started, would be
to put a database in the middle. User makes selections on the admin
form and writes info to the database. The salesman form polls the
database on regular basis, and when it finds new information it
displays it on the salesman form.

This should be enough to get you started.
 
Hi,

It sounds like you should be using a central server.

If you want to use remoting, each client that logs in can establish a
remoting session with a central server via a well known IP address. The
client can pass information about its own remoting service being hosted
locally so that the central server can establish a remoting connection back
to the client. The server will have to maintain a list of client remoting
objects as well as its own hosted object to which clients connect.

The remoting server can act to dispatch incoming messages to its clients.

You'll need to configure a class that derives from MarshalByRefObject to be
hosted as a server-activated SingleCall or Singleton (preferred).

".NET Remoting Overview"
http://msdn2.microsoft.com/en-us/library/kwdt6w2k.aspx

You could do this on a lower level using Sockets too:

"TcpListener Class"
http://msdn.microsoft.com/library/d...etSocketsTcpListenerClassTopic.asp?frame=true
 
Thanks but i don't know how to interface with databases in c# express.

I tried sometime ago to interface with a mysql database but got stuck
somewhere along the way. I don't want to use ms sql server because of
the licencing requirements.

Thanks, any further advice would be appreciated.
 
Its fairly simply; you use SqlClient (For sql server) or OdbcClient or
OleDbClient (if mysql supports oledb) to talk to the database. Just
look at Ado.net topics.

Out of curiosity, what licensing requirements do you not care for in
Sql Server Express?

Andy
 
I understood that the database size was limited when i last looked into
this about a year ago. And didn't like the idea of having to pay if the
database happened to grow beyond the limit.

Also - It was my understanding that if i distributed programs that
utilised an sql database, each user would have to install sql server
express - and as this can be taken out of the public domain at any
time, i didn't think this was a viable option.

I'm sure i've missed the point somewhere along the way - please feel
free to to educate me!

Thankyou.
 
Thanks very much - i'll investage remoting further and try that route!
 
I've tried following a simple .net remoting starter. And the code isn't
compiling. Complaining that it doesn't know about the namespace HTTP.
Can anyone suggest why this isn't working?

The tutorial i'm using is here:
http://www.c-sharpcorner.com/Network/RemotingInNETM.asp

Excerpt: -

Step 1: Creating the Server Server.cs On Machine1
--------------------------------------------------------------------------------
I've coded the following file : -

using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.HTTP;
namespace Server
{
public class ServiceClass : MarshalByRefObject {
public void AddMessage (String msg)
{
Console.WriteLine (msg);
}
}
public class ServerClass
{
public static void Main ()
{
HTTPChannel c = new HTTPChannel (1095);
ChannelServices.RegisterChannel (c);
RemotingServices.RegisterWellKnownType
("Server","Server.ServiceClass","ServiceClass",WellKnownObjectMode.Singleton);
Console.WriteLine ("Server ON at 1095");
Console.WriteLine ("Press enter to stop the server...");
Console.ReadLine ();
}
}
}


Save this file as Server.cs
Compile this file using

csc /r:system.runtime.remoting.dll /r:system.dll Server.cs
-------------------------------------------------------------------------------------

When I try to compile it i get the message error CS0234 the type or
namespace name 'HTTP' does not exist in the namespace
'System.Runtime.Remoting.Channels' (are you missing an assembly
reference?)

Any suggestions please?
 
Hi,

HTTP should be Http - it's case sensitive.

Also, there is a newsgroup that may help you with your remoting-specific
questions in the future:

news://news.microsoft.com/microsoft.public.dotnet.framework.remoting
 
Thanks very much - in future i will post in that group.

I have tried your change and now am getting a different error.

I now have: -

---
using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Http;
namespace Server
{
public class ServiceClass : MarshalByRefObject {
public void AddMessage (String msg)
{
Console.WriteLine (msg);
}
}
public class ServerClass
{
public static void Main ()
{
HttpChannel c = new HttpChannel (1095);
ChannelServices.RegisterChannel (c);
RemotingServices.RegisterWellKnownType
("Server","Server.ServiceClass","ServiceClass",WellKnownObjectMode.Singleton);
Console.WriteLine ("Server ON at 1095");
Console.WriteLine ("Press enter to stop the server...");
Console.ReadLine ();
}
}
}
===========
And am getting the error 'the name ChannelServices' does not exist in
the current context.

And also System.Runtime.Remoting.RemotingServices does not contain a
defintion for RegisterWellKnownType.
==============

Thanks Again-
 
Hi,
And am getting the error 'the name ChannelServices' does not exist in
the current context.

You're missing another "using" directive:

using System.Runtime.Remoting.Channels;

These directives tell the C# compiler where to look for unqualified tokens
in the code such as, "ChannelServices", which is located in the namespace
I've given above. Without telling the compiler to look in that namespace
the ChannelServices class won't be found.
And also System.Runtime.Remoting.RemotingServices does not contain a
defintion for RegisterWellKnownType.

System.Runtime.Remoting.RemotingServices does not contain a member named
RegisterWellKnownType :)

You probably want the RegisterWellKnownServiceType method.

If you're not using Visual Studio then you can still discover the members of
any Type in the framework on http://msdn.microsoft.com; just search for the
name of the class in which you're interested and click the link that looks
like, "TheClassName Class" or "TheClassName Members", for example.

A better approach might be to install Visual C# 2005 Express:

"Visual C# 2005 Express"
http://msdn.microsoft.com/vstudio/express/visualcsharp/

Intellisense would have helped you solve the last problem far quicker than
newsgroups, I'm sure. The Object Browser or the new smart tag feature could
have easily helped you solve the first problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top