By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,987 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,987 IT Pros & Developers. It's quick & easy.

Remoting - Is server running?

P: n/a
I have a number of applications that need to access the same object at
different times and any one of these programs may be running at any one
time. I do not have a specific application that could act as the
server. So I want to give each application the capability of being the
server and the first one to start gets the job.

Unfortunately to do this I need some way of detecting whether a server
is already running. I was hoping that Activator.GetObject() might
return null if there is no server but it just returns a usless object
that throws an exception every time you try and use it.

Is there any way without using exceptions (which are slow and horrible)
to find out if another server is running?

I have posted my code bellow to help you understand what I mean. Both
functions are calling by any program wishing to access the remoted
object.

I also have the same problem with Channels.

Thanks for any help!

Olie

public void StartService(string Name,Type type)
{
if (_ServerChannel == null)
{
try
{
BinaryClientFormatterSinkProvider ClientProvider =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider =
new BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();

ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilter Level.Full;
Properties["port"] = xxxx;
Properties["name"] = "xxxx";
Properties["typeFilterLevel"] = "Full";
_ServerChannel = new TcpChannel(Properties,
ClientProvider, ServerProvider);

ChannelServices.RegisterChannel(_ServerChannel);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}

RemotingConfiguration.RegisterWellKnownServiceType (type,
Name, WellKnownObjectMode.Singleton);
}

public void ConnectToService(string Url, string Name, Type
type, ref XxxxService Endpoint)
{
if (_Channel == null)
{
BinaryClientFormatterSinkProvider ClientProvider = new
BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider = new
BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();

ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilter Level.Full;
Properties["port"] = 0;
_Channel = new TcpChannel(Properties, ClientProvider,
ServerProvider);

ChannelServices.RegisterChannel(_Channel);
}

Endpoint = (AcwService)Activator.GetObject(type, "tcp://" +
Url + ":xxxx/" + Name);

Register(Endpoint);
}

Apr 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Olie" <ow****@gmail.com> wrote in news:1144065596.438605.261230
@i39g2000cwa.googlegroups.com:
I have a number of applications that need to access the same object at
different times and any one of these programs may be running at any one
time. I do not have a specific application that could act as the
server. So I want to give each application the capability of being the
server and the first one to start gets the job.


I couldn't quite tell from your post if you meant that all applications are
running on the same machine (as would perhaps be implied in the above
paragraph) or if they are running on different machines (as would be
implied by the fact that you are trying to use remoting to synchronize.)

If they are all running on one machine and you are just using remoting to
connect to a local object, then perhaps a named mutex would work better.
The url below describes using named mutexes to implement single-instance
application instantiation, but you could easily adapt it so that several
applications run with knowledge of whether your other applications are
running.

http://odetocode.com/Blogs/scott/arc...08/20/401.aspx

-mdb
Apr 3 '06 #2

P: n/a
Perhaps why you are getting confused is that the software is designed
to both work locally and remotly.

I also believe that remoting supports other features such as events
which mutexs would not.

Apr 3 '06 #3

P: n/a
I have a similar situation but not exactly the same. In my case i can
have multiple servers and many multiple clients. I used UDP for everyone
to find out about each other. The servers identify themselves
periodically. They can also respond to an immediate request for
identification from any client.
In your case you can have your server try to start and do the following
logic
1) Try to open udp channel. If this fail a server is already running on
this machine.
2) Send an identification request over UDP to see if a server responds.
If no response become the servers.

Hope this helps
Leon Lambert

Olie wrote:
I have a number of applications that need to access the same object at
different times and any one of these programs may be running at any one
time. I do not have a specific application that could act as the
server. So I want to give each application the capability of being the
server and the first one to start gets the job.

Unfortunately to do this I need some way of detecting whether a server
is already running. I was hoping that Activator.GetObject() might
return null if there is no server but it just returns a usless object
that throws an exception every time you try and use it.

Is there any way without using exceptions (which are slow and horrible)
to find out if another server is running?

I have posted my code bellow to help you understand what I mean. Both
functions are calling by any program wishing to access the remoted
object.

I also have the same problem with Channels.

Thanks for any help!

Olie

public void StartService(string Name,Type type)
{
if (_ServerChannel == null)
{
try
{
BinaryClientFormatterSinkProvider ClientProvider =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider =
new BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();

ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilter Level.Full;
Properties["port"] = xxxx;
Properties["name"] = "xxxx";
Properties["typeFilterLevel"] = "Full";
_ServerChannel = new TcpChannel(Properties,
ClientProvider, ServerProvider);

ChannelServices.RegisterChannel(_ServerChannel);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}

RemotingConfiguration.RegisterWellKnownServiceType (type,
Name, WellKnownObjectMode.Singleton);
}

public void ConnectToService(string Url, string Name, Type
type, ref XxxxService Endpoint)
{
if (_Channel == null)
{
BinaryClientFormatterSinkProvider ClientProvider = new
BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider = new
BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();

ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilter Level.Full;
Properties["port"] = 0;
_Channel = new TcpChannel(Properties, ClientProvider,
ServerProvider);

ChannelServices.RegisterChannel(_Channel);
}

Endpoint = (AcwService)Activator.GetObject(type, "tcp://" +
Url + ":xxxx/" + Name);

Register(Endpoint);
}

Apr 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.