473,785 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remoting and calling functions in another class

What I want to do is call a function in my main form/class from the
server (which the another program/client calls). The main form does
not really create a server object so I can't pass the frmForm class
into the constructor of MyServer (the client side would have no idea
what to pass into that anyways). What other way to do this is there?
I guess there is static functions, but I can't make everything in
those functions static.

namespace Mark
{
public class frmForm : System.Windows. Forms.Form
{
private void frmForm_Load(ob ject sender, System.EventArg s e)
{
HttpChannel channel = new HttpChannel(800 1); //Create a new
channel
ChannelServices .RegisterChanne l (channel); //Register channel
RemotingConfigu ration.Register WellKnownServic eType(typeof (MyServer),"MyS erver",WellKnow nObjectMode.Sin gleton);
}
public void Function1()
{
//do some non-static stuff here
}
}

public class MyServer: MarshalByRefObj ect
{
public void CalledByClient( )
{
//want to call frmForm.Functio n1 here
}
}
}
Nov 16 '05 #1
5 3974
Well MyServer is a singleton how about getting the form to achieve the same
effect by manually marshallingobje ct into the remoting infrastructure.

instead of using RegisterWellKno wnServicetype, create an instance of
MyServer pass itself into the ctor and then call
RemotingService s.Marshal passing the instance.

Its proably a good idea in this case to override InitializeLifet imeServices
in MyServer and return null. This will disable the lease based distributed
garbage collection of remoting which in this case is probably a good idea.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Mark" <ms****@yahoo.c om> wrote in message
news:89******** *************** ***@posting.goo gle.com...
What I want to do is call a function in my main form/class from the
server (which the another program/client calls). The main form does
not really create a server object so I can't pass the frmForm class
into the constructor of MyServer (the client side would have no idea
what to pass into that anyways). What other way to do this is there?
I guess there is static functions, but I can't make everything in
those functions static.

namespace Mark
{
public class frmForm : System.Windows. Forms.Form
{
private void frmForm_Load(ob ject sender, System.EventArg s e)
{
HttpChannel channel = new HttpChannel(800 1); //Create a new
channel
ChannelServices .RegisterChanne l (channel); //Register channel
RemotingConfigu ration.Register WellKnownServic eType(typeof
(MyServer),"MyS erver",WellKnow nObjectMode.Sin gleton);
}
public void Function1()
{
//do some non-static stuff here
}
}

public class MyServer: MarshalByRefObj ect
{
public void CalledByClient( )
{
//want to call frmForm.Functio n1 here
}
}
}

Nov 16 '05 #2
"Richard Blewett" <ri*****@dotnet consult.co.uk> wrote in message news:<u0******* *******@TK2MSFT NGP14.phx.gbl>. ..
Well MyServer is a singleton how about getting the form to achieve the same
effect by manually marshallingobje ct into the remoting infrastructure.

instead of using RegisterWellKno wnServicetype, create an instance of
MyServer pass itself into the ctor and then call
RemotingService s.Marshal passing the instance.

Its proably a good idea in this case to override InitializeLifet imeServices
in MyServer and return null. This will disable the lease based distributed
garbage collection of remoting which in this case is probably a good idea.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog


So would I do something like?

MyServer svr = new MyServer();
svr.PassFormOve r(this);
ObjRef objrefWellKnown = RemotingService s.Marshal(svr, ???????);

What do I put for the other arguments?

I would of course put something like

public class MyServer: MarshalByRefObj ect
{
static public Mark.frmForm frmMyForm;

public void PassFormOver(Ma rk.frmForm frm)
{
frmMyForm = frm;
}

public void CalledByClient( )
{
//want to call frmForm.Functio n1 here
}
}
}
Nov 16 '05 #3
HttpChannel channel = new HttpChannel(800 1);
MyServer ms = new MyServer(this);
RemotingService s.Marshal(ms, "MyServer") ;
ChannelServices .RegisterChanne l (channel); //Register channel

you basically provide the same info as with RegisterWellKno wnServiceType but
*you* create the instance rather than the remoting infrastructure. And as
you can see I'd probably create a ctor on MyServer which took an instance of
your form.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Mark" <ms****@yahoo.c om> wrote in message
news:89******** *************** ***@posting.goo gle.com...
"Richard Blewett" <ri*****@dotnet consult.co.uk> wrote in message
news:<u0******* *******@TK2MSFT NGP14.phx.gbl>. ..
Well MyServer is a singleton how about getting the form to achieve the
same
effect by manually marshallingobje ct into the remoting infrastructure.

instead of using RegisterWellKno wnServicetype, create an instance of
MyServer pass itself into the ctor and then call
RemotingService s.Marshal passing the instance.

Its proably a good idea in this case to override
InitializeLifet imeServices
in MyServer and return null. This will disable the lease based
distributed
garbage collection of remoting which in this case is probably a good
idea.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog


So would I do something like?

MyServer svr = new MyServer();
svr.PassFormOve r(this);
ObjRef objrefWellKnown = RemotingService s.Marshal(svr, ???????);

What do I put for the other arguments?

I would of course put something like

public class MyServer: MarshalByRefObj ect
{
static public Mark.frmForm frmMyForm;

public void PassFormOver(Ma rk.frmForm frm)
{
frmMyForm = frm;
}

public void CalledByClient( )
{
//want to call frmForm.Functio n1 here
}
}
}

Nov 16 '05 #4
That seems to work. Thanks. One more question though. How does it
know it's a singleton? Sorry if it's a rookie question but this is my
first time working with remoting. Does it also already know it's a
WellKnownServic eType?

"Richard Blewett" <ri*****@dotnet consult.co.uk> wrote in message news:<uY******* ******@tk2msftn gp13.phx.gbl>.. .
HttpChannel channel = new HttpChannel(800 1);
MyServer ms = new MyServer(this);
RemotingService s.Marshal(ms, "MyServer") ;
ChannelServices .RegisterChanne l (channel); //Register channel

Nov 16 '05 #5
That seems to work. Thanks. One more question though. How does it
know it's a singleton? Sorry if it's a rookie question but this is my
first time working with remoting. Does it also already know it's a
WellKnownServic eType?

"Richard Blewett" <ri*****@dotnet consult.co.uk> wrote in message news:<uY******* ******@tk2msftn gp13.phx.gbl>.. .
HttpChannel channel = new HttpChannel(800 1);
MyServer ms = new MyServer(this);
RemotingService s.Marshal(ms, "MyServer") ;
ChannelServices .RegisterChanne l (channel); //Register channel

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
298
by: Tom | last post by:
Hi friends I am new to remoting so this may sound silly. I don't understand remoting, I think its suppose to be client / server but why is it that you always need to attach somesort of service.dll to both the client and the server ? so what I don't understand is how can I implement server logic on client calls if the dll must be attached to both the client and the server ? say if I want to perform some sql queries on the server and I...
5
7421
by: Sam Martin | last post by:
Hi All, I've got a problem where my application loads an assembly in the running AppDomain when it shouldn't. Ok, I've got a RemotingHost application that configs the remoting stuff and then... asks the user for a list of .net DLLs. the app then copies a these assemblies to a cache folder along with my RemotingClient app. Once copies i config a AppDomain setup and create a new
6
2717
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or rmi. Just to keep my question short I am posting trimmed version of my code. //file: Serializable.cs
15
5753
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the remote publisher, so I used delegate that the user will be able to set on it his own function for that purpuse. The trouble is that this delegate must not be static because there may be many subscribers, and each subscriber may have different...
3
1292
by: Fireangel | last post by:
I'm tying to build a simple Remoting thingie (techincal term). However, I can't seam to get it to compile. ChatBase is defined as a public class.. The line that kills compiling: theChatStuff = (ChatBase *) ( Activator::GetObject ( __typeof ( ChatBase ) , "tcp://localhost:9999/Try1") );
1
2089
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 UI for interacting with the instruments. Readings from the instruments are periodically sent to the clients, and clients will send commands to the server based on user input. In normal usage there will be around 6 clients connected, with a...
3
2233
by: Michel Smit | last post by:
I'm running into another problem with my component. I'm trying to use .NET remoting to avoid complex firewall issues. I have a webserver which is the client machine and a database server which is the server machine. On the database server I have created a Windows Service which binds a component to port 42525 using TCP. The component involved contains a reference to a VB6 DLL in which are some functions used by the component.
8
4154
by: nyhetsgrupper | last post by:
I have written a windows service and want to expose a web based user interface for this service. I then wrote a class library containing a ..net remoting server. The class library have a method named StartRemotingServer(). To be able to call this method from the windows service I need to reference the remoting class library, but for the class library to be able to access the internal structures of the windows service the class library...
7
2176
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am trying to see if I can call a Library remotely. The library contains a Form that I want to display then pass back some data to user that called this form remotely. I have it working some-what. I am able to call form remotely and return data to client but somewhere after closing remote form and returning data - I get a Windows exception -
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.