|
I'm having an issue trying to get my clients to handle messages that are passed from a server to a shared object... Any remoting gurus out there are free to enlighten me...
Ok.. First of all, here is the interface created to by implemented by the remote object:
namespace WarComInterface<br />
{<br />
<br />
public delegate void ServerToClientEvent(object sender, ServerToClientEventArgs e);<br />
<br />
public interface ICom<br />
{<br />
Joueur clientReqJoueur(string nomJoueur);<br />
<br />
event ServerToClientEvent ServerToClientMsg;<br />
<br />
void clientMsg(EventTypes.EventsFromClient typeEvent, string nomJoueur);<br />
}<br />
}
Now, here is the part where the client gets a reference to the remote object and sets a handler to listen for events coming from the server:
<br />
try<br />
{<br />
TcpChannel channel = new TcpChannel();<br />
ChannelServices.RegisterChannel(channel, false);<br />
remoteComm = (WarComInterface.ICom)Activator.GetObject(typeof(WarComInterface.ICom),<br />
"tcp://"+txt_adrip.Text + ":1069/jh");<br />
<br />
remoteComm.ServerToClientMsg += new ServerToClientEvent(MessageFromServer);<br />
<br />
And finally, this is the part inside the shared object. It's within a public method called by the server (some sort of public void sendMsg() )
<br />
evArg = new ServerToClientEventArgs(EventTypes.EventsFromServer.UpdateStats, targetPlayer);<br />
if (ServerToClientMsg != null)<br />
{<br />
ServerToClientMsg(this, evArg); <br />
}<br />
It fires up the following exception : This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.
Any help would be greatly appreciated!
|
|
|
|
|
I've seen that message. For me, it meant that the client was not defining a suitable channel for the event callbacks. What makes yours "unsuitable" might be the absence of a channel altogether (which I doubt, looking at your sample), permissions (which I don't understand), or the absence of the typeFilterLevel attribute for the channel. In the server's config file, the latter would look like:
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
|
|
|
|
|
Hello everyone,
How can I get the focus on a Window Form? This is my problem. I have created a Media Player using DirectShow in C# enviroment. When I use the full-screen mode and enlarge the screen after reducing the size to normal, no longer I can have any form open on the TOP of the other windows.
Thank you very much and have a great day,
Khoramdin
|
|
|
|
|
This means your form is topmost. You can change ths property.
Or do you mean forms in your program ? If the form is modal, then it takes the focus and no other form can be accessed.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello Christian,
Thanx for the reply. You were absolutly correct. I checked the codes and realised where the prroblem was.
Thank you for the help.
Khoramdin
|
|
|
|
|
Is there a way to change a color with a number in code? It's confusing, but I want to set a timer to change 1 of the 3 color parts, and I just need to know how to reach them. Thanks in advance.
The most knowledge doesn't mean the most wise...
|
|
|
|
|
Hi,
try this:
Color color;
...
int red=color.Red+1;
if (red>255) red=255;
int green=color.Green;
int blue=color.Blue-1;
if (blue<0) blue=0;
color=Color.FromArgb(red, green, blue);
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks, Luc.
The most knowledge doesn't mean the most wise...
|
|
|
|
|
Hw do I set that to the forms backcolor?
The most knowledge doesn't mean the most wise...
|
|
|
|
|
Hi,
the main thread simply does myForm.BackColor=color;
for animation purposes, I prefer the Windows.Forms.Timer timer; other timers tick
on a different thread and would need Control.InvokeRequired and Control.Invoke()
to touch the Form.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Is there any way to make a method that the form continuously calls on? Or, is there a way to make a method that it calls without you having to call it? Like, Say how Form1_Load gets called on its own, is there a way to do that with a method you make? I hope that didn't come out too confusing, much thanks in advance.
-- modified at 17:00 Wednesday 24th October, 2007
The most knowledge doesn't mean the most wise...
|
|
|
|
|
To create a method that form continuosly calls you have to create a timer object, and initalize it on constructor or form load.
See and example here http://www.csharphelp.com/archives/archive90.html
Visit my blog at http://dotnetforeveryone.blogspot.com
|
|
|
|
|
Thanks.
The most knowledge doesn't mean the most wise...
|
|
|
|
|
Also, for simple timer methods, I like to use anonymous delegates. Like this:
myTimer.Tick += delegate { Invalidate(); };
The invalidate is just the sample code inside the anonymous delegate, you can put anything there.
When you do this, any variables created inside the method that defnes the delegate are in scope, but I like it more because it defines what the timer does at the point that I create it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello, I am a beginning C# programming student at a university and I'm having trouble making a previous program of mine modular. We wrote a program that calculated an employee's net pay, and now we have to make it modular by adding 3 methods. I've done just as the examples are in our notes and all I get is an error saying invalid namespace. Here is my original code:
<pre>
using System;
using System.Collections.Generic;
using System.Text;
namespace Program5
{
class Program
{
const double DEPINS = 25.50;
const double TAX = .23;
static void Main()
{
int dep;
double grossPay, hourRate, hourWorked, deduct, netPay, depIns, tax;
Console.Write("Hours Worked: ");
hourWorked = Double.Parse(Console.ReadLine());
Console.Write("Hourly Rate: ");
hourRate = Double.Parse(Console.ReadLine());
Console.Write("Dependents: ");
dep = Int32.Parse(Console.ReadLine());
if (hourWorked >= 40)
grossPay = Math.Round(1.5 * hourRate * hourWorked, 2);
else
grossPay = Math.Round(hourRate * hourWorked, 2);
depIns = dep * DEPINS;
tax = grossPay * TAX;
deduct = Math.Round(depIns + tax, 2);
netPay = grossPay - deduct;
Console.WriteLine("");
Console.WriteLine("Hours Worked: {0,9:n}", hourWorked);
Console.WriteLine("Hourly Rate: {0,9:n}", hourRate);
Console.WriteLine("Dependents: {0,9}", dep);
Console.WriteLine("Gross Pay: {0,9:n}", grossPay);
Console.WriteLine("Deductions: {0,9:n}", deduct);
Console.WriteLine(" ---------");
Console.WriteLine("Net Pay: {0,9:c}", netPay);
}
}
}
</pre>
Thanks!
|
|
|
|
|
If I cut and paste your example code it compiles fine. What are you using to compile the code? Does it say which namespace is invalid? Or a line number?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Yeah, it compiles fine because I copy and pasted the original coding without what I put in when I tried to make it modular. What I tried to do looked something like this:
<pre>
using System;
using System.Collections.Generic;
using System.Text;
namespace Program5
{
class Program
{
const double DEPINS = 25.50;
const double TAX = .23;
static void GetData()
{
int dep;
double grossPay, hourRate, hourWorked, deduct, netPay, depIns, tax;
Console.Write("Hours Worked: ");
hourWorked = Double.Parse(Console.ReadLine());
Console.Write("Hourly Rate: ");
hourRate = Double.Parse(Console.ReadLine());
Console.Write("Dependents: ");
dep = Int32.Parse(Console.ReadLine());
}
static void CalcNet()
{
if (hourWorked >= 40)
grossPay = Math.Round(1.5 * hourRate * hourWorked, 2);
else
grossPay = Math.Round(hourRate * hourWorked, 2);
depIns = dep * DEPINS;
tax = grossPay * TAX;
deduct = Math.Round(depIns + tax, 2);
netPay = grossPay - deduct;
}
static void DspData()
{
Console.WriteLine("");
Console.WriteLine("Hours Worked: {0,9:n}", hourWorked);
Console.WriteLine("Hourly Rate: {0,9:n}", hourRate);
Console.WriteLine("Dependents: {0,9}", dep);
Console.WriteLine("Gross Pay: {0,9:n}", grossPay);
Console.WriteLine("Deductions: {0,9:n}", deduct);
Console.WriteLine(" ---------");
Console.WriteLine("Net Pay: {0,9:c}", netPay);
}
static void Main ()
{
GetData();
CalcNet();
DspData();
}
</pre>
So what I did is I set it up exactly like it was set up in an example program from my notes which I copy and pasted and compiled and that worked just fine, but when I do it with this program it says my namespace is invalid and that I need a semi-colon after the static void's which I know is incorrect. So I have no idea what is going on.
|
|
|
|
|
in the above code you should get a ton of errors and not just invalid namespace.
you have defined variables like hourWorked, hourRate etc in the function "GetData()" and try to access it from other functions. those variables will have scope in only GetData() function and hence are not accessible in other functions.
so, either you can pass the variables as arguments to the functions or do not make your functions static.
hope this helps.
regards
|
|
|
|
|
Okay, I fixed the defined variables...but now I get a bunch of errors saying invalid "{"'s and "}"'s after the methods and stuff plus "expected class, delegate, enum, interface, or struct" for the voids. And this is what I've got for coding:
using System;
using System.Collections.Generic;
using System.Text;
namespace Program5
{
class Program
{
const double DEPINS = 25.50;
const double TAX = .23;
int dep;
double grossPay, hourRate, hourWorked, deduct, netPay, depIns, tax;
static void getData()
{
Console.Write("Hours Worked: ");
hourWorked = Double.Parse(Console.ReadLine());
Console.Write("Hourly Rate: ");
hourRate = Double.Parse(Console.ReadLine());
Console.Write("Dependents: ");
dep = Int32.Parse(Console.ReadLine());
}
static void calcNet()
{
if (hourWorked >= 40)
grossPay = Math.Round(1.5 * hourRate * hourWorked, 2);
else
grossPay = Math.Round(hourRate * hourWorked, 2);
depIns = dep * DEPINS;
tax = grossPay * TAX;
deduct = Math.Round(depIns + tax, 2);
netPay = grossPay - deduct;
}
static void dspData();
{
Console.WriteLine("");
Console.WriteLine("Hours Worked: {0,9:n}", hourWorked);
Console.WriteLine("Hourly Rate: {0,9:n}", hourRate);
Console.WriteLine("Dependents: {0,9}", dep);
Console.WriteLine("Gross Pay: {0,9:n}", grossPay);
Console.WriteLine("Deductions: {0,9:n}", deduct);
Console.WriteLine(" ---------");
Console.WriteLine("Net Pay: {0,9:c}", netPay);
}
static void Main();
{
getData()
calcNet()
dspData()
}
}
}
|
|
|
|
|
this still has problems.
murtle3 wrote: static void dspData();
remove ';' after the function name.
murtle3 wrote: static void Main();
{
getData()
calcNet()
dspData()
}
remove ';' after Main() and add ';' after all the function calls.
after all this is done you should note that you are trying to access the class variables from static method. this is not possible.
a static method can access static variables. what you should do is make the variables static (not a good way of programming), but it should help you run the program.
instead of:
murtle3 wrote: int dep;
double grossPay, hourRate, hourWorked, deduct, netPay, depIns, tax;
try the following:
static int dep;
static double grossPay, hourRate, hourWorked, deduct, netPay, depIns, tax;
hope this helps.
regards
|
|
|
|
|
Alright, I got it to work. Thanks a lot guys for your help!
|
|
|
|
|
You should use tryparse to read lnes, in case someone enters text instead of a number. You have not pasted the whole program, b/c there's nothing modular about this, it's all one method.
murtle3 wrote: nt dep;
double grossPay, hourRate, hourWorked, deduct, netPay, depIns, tax;
This is bad practice, declare variables as you give them values, not in a bunch at the top. If your teacher tells you to do it this way, tell him that C required this, but C# does not, and doing it only increases the scope of your variables, making debugging harder.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
I have a RichTextBox with some information about colors in the text stored as Rtf. Now I'd like to remove for example first 1000 chars from the text without loosing information about colors in rest of the text. Is it possible?
Thanks
Pawel
|
|
|
|
|
You should be able to use the Select[^] method to select the text you want to remove, then set the SelectedText[^] property to String.Empty (or "").
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks. Works fine.
Pawel
|
|
|
|
|