473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Remoting - Is server running?

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
3 3862
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Data | last post by:
In my project I want to execute some commands on the remote machine. I am using .Net Remoting to achieve this. My server which is an exe is copied on the remote machine and it receives command from...
3
by: Patty O'Dors | last post by:
Hi I posted a similar question like this to a reply to another thread but it wasn't really relevant to that thread and I don't think anybody read it so I'm posting a new one. I'm trying to...
4
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give...
1
by: David Krmpotic | last post by:
Hi All! I have a .NET remoting Client-Server application with Server Activated Objects only.. something is worrying me.. sometimes (rarely), I can't connect to the server although it is...
0
by: Felipe Garcia | last post by:
I've built a system in myjob that does the following: We have a page with frames one frame loads the default.aspx and the other frame loads the events.aspx. Inside events.aspx we have a loop...
15
by: Ron L | last post by:
We are working on a distributed VB.Net application which will access a SQL database located on a known server. Each client will run on the user's local machine. To implement this, we are trying...
5
by: LGHummel | last post by:
I'm trying to host a remoting app in IIS and am getting the following error: Failed to execute the request because the ASP.NET process identity does not have read permissions to the global...
4
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
1
by: Thomee Wright | last post by:
I'm having a problem with a pair of applications I'm developing. I have a server application which interacts with several instruments, and a client app which connects to the server and provides a...
1
by: Derrick | last post by:
Hello all; I'm having a bit of trouble with .NET remoting. Here's my scenario: I have a "remotable" type which is served by a Windows Service. I have a WinForms app which consumes the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.