|
I have been searching all over trying to find some easy good network code examples.
Basicly, I am creating (Only for learning purposes) a simple card game. I have the client side pretty much finished, trying to get the server working. My goal was to have 2 games going at once (Seperate timer for each). After 10 seconds (For that game), it will switch to the next players turn if they didn't select any cards.
What I can't figure out, or find anywhere is a good example of code that shows how a request from 1 client, can be forwarded to another client. Another thing would be for the "game timer" to tell all the clients in that game a players turn was skipped.
Even a simple example of a "telnet chatroom" would work. Multiple clients connect to the server, then all messages are forwarded to all connecting clients would be a step in the right direction.
I am fairly new at C#, with a primarly Perl / PHP background. So, please go easy on me :P
|
|
|
|
|
Are you using remoting ?
If you are, then you can't really send a message from one client to another.
Just pass it through the server.
When it's player 1 turn, server calls
client_1_proxy.TimerStart();
When player 1 clicks client calls :
server_proxy.Played();
Or if the 10 seconds run out :
server_proxy.TimeOver();
Then server checks whoses turn it is, and go over with client_x_proxy.TimerStart()...
It will probably be easier to go with persistant server object, so you don't have to store game state in a file or something.
Etienne.
|
|
|
|
|
Yes, that is what I planned on doing. The server is going to reply the messages, because the server still needs to verify that its a vaild move.
The timer code, I can figure out for the most part. The main issue I need help with, is the network code it self. I have a few examples, some using threads, some note. Some have like 5 different classes, some less.
I need to be to keep track of multiple (Persistant) connections. When the server decides to change the game state (Player moves, players skipped, etc) it needs to let all clients, or only some clients in that game know. (My longer goal was to run 2 or more games at once)
I figured having a seperate class to define the game state information. Client "id"s that are connected, which players have which cards, last card dropped, which players turn it presently is, etc. Then have a timer that interacts with that class. This timer is only for this game instance. When the state changes, it doesn't affect other games.
I hope that explains what my goal is a little more.
|
|
|
|
|
I have the disc, installed it, but can't find any samples anywhere ? Where are they ? Or if there aren't any, where can I find some on internet ? I tried the ones that are built for Longhorn but they won't compile as the CTP (for XP) has some fundamental changes in it (like namespace changes, some features cut-off and so on).
Regards, Desmond
|
|
|
|
|
Hi,
I have an application where I dynamically build a form based on a selection made in a database tree. All controls added to the form are docked at the top. It all works except for the speed. I am using the suspend and resume layout but that still doesn't address the drawing speed. All my controls are also built using the default windows control.
Does anyone know why the controls are so slow to add to a form dynamically?
Is there anything I can do?
Thanks!
|
|
|
|
|
|
I'd suggest sending a WM_SETDRAW message to stop redrawing the form while you're adding the controls.
Another simpler suggestion (and, depending on your code, can give performance enough) is doing all the manipulation on the controls before you call Controls.Add, so it'll minimize redrawing.
BTW, 99% of the "slow dynamic controls" posts I answer here are performance problems within the generation of the controls, i.e., in your data access code, and not a .NET framework performance problem.
Yes, even I am blogging now!
|
|
|
|
|
Thanks I will the WM_SETDRAW.
As for doing the manipulation before the controls.add, it turns out I use the AddRange and all the controls are ready before the AddRange.
I did some test without any data access, just the actual creation of the control and no speed improvement in my case. Granted I have some methods that go fetch the appropriate control for the data I am viewing but it only loops through a dozen controls at the moment.
The application is usable but I see the drawing of the elements as they get added to the form. I thought that the SuspendLayout and ResumeLayout would take care of that.
|
|
|
|
|
to make your own easily couldn't you just make a tabpage, edit everything hide the buttons, and add some pics to make it look like its static and couldn;t you just set the next page when the next is displayed?? is this how it works or are there other tricks.
IM PROUD TO BE A GMAIL;
|
|
|
|
|
|
Greetings, all!
I'm trying to change the background color on a TabControl, as you may have guessed from the subject. I see that it inherits from Control, which has a BackColor property, but that property doesn't seem to be exposed in the TabControl. I can change the BackColor for the individual TabPages in the control, but unless I can change the TabControl's BackColor, it looks terrible.
So, the question is, how do I change the BackColor (and ForeColor, for that matter) in a TabControl?
|
|
|
|
|
P.S. I tried casting the TabControl to Control, and setting the BackColor on the cast. No luck.
|
|
|
|
|
Hi
How are you?
I need to hide certain properites of an object when i change a property value e.g.
enum ObjType
{TypeA,TypeB}
public ObjType Type
{
get {...}
Set {...}
}
As i change value of Type Property of an Object i want to hide some browsable properties or show some browsable(false) properties
C#
|
|
|
|
|
|
Sorry
i need to dynamically hide and show properties in the property grid at run time
like using attribute browsable false and true
|
|
|
|
|
I needed to do something similar. You'll need to implement the ICustomTypeDescriptor interface (here's an article that shows how).
In ICustomTypeDescriptor 's GetProperties() method you can set which properties will show up in the PropertyGrid (see my articles demo source for an example).
So using your example, you could do something like:
TypeACustomTypeDescriptor typeATypeDescriptor = new TypeACustomTypeDescriptor();<br />
TypeBCustomTypeDescriptor typeBTypeDescriptor = new TypeBCustomTypeDescriptor();<br />
<br />
public ObjType Type<br />
{<br />
get {...}<br />
set <br />
{<br />
if (value == ObjType.TypeA)<br />
{<br />
PropertyGrid.SelectedObject = typeATypeDescriptor;<br />
}<br />
else<br />
{<br />
PropertyGrid.SelectedObject = typeBTypeDescriptor;<br />
}<br />
}<br />
}
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
Hi
Sir How are you ?
Thank alot it works as i needed
thank you again
best wishes
Ali
VC++,COM ,C#
|
|
|
|
|
Hi,
i have created a stored procedure which returns number of un-read memo(s).....
stored procedure's code :
----------------------------
CREATE PROCEDURE spNumOfUnReadMemos
@EmpTo char(6), @NumOfUnReadMemos int OUTPUT
AS
SELECT COUNT(EmpTo) FROM tblMemoManagement WHERE
EmpTo=@EmpTo AND ReadYesNo='NO'
RETURN;
GO
---------------------------------------
Then i have a C# Class which access this stored procedure as
public int getNumUnReadMemos() {
int retVal=0;
try {
//create the sql
sql = "spNumOfUnReadMemos";
//open the connection
gICVars.scInCtrl.Open();
//create the command
cmdMemo = new SqlCommand(sql,gICVars.scInCtrl);
cmdMemo.CommandType=CommandType.StoredProcedure;
//create the parameters
cmdMemo.Parameters.Add("@EmpTo", SqlDbType.Char,6);
cmdMemo.Parameters[0].Value=this.getToEmp();
cmdMemo.Parameters.Add("@NumOfUnReadMemos", SqlDbType.Int,4);
cmdMemo.Parameters[1].Direction=ParameterDirection.Output;
//execute the non-query
cmdMemo.ExecuteNonQuery();
//retrieve the value of NumOfUnReadMemos
Console.WriteLine(cmdMemo.Parameters[1].Value);
//retVal = int.Parse(cmdMemo.Parameters[1].Value.ToString());
Console.WriteLine(cmdMemo.Parameters[1].Value);
//clean up code
cmdMemo.Dispose();
sql=null;
gICVars.scInCtrl.Close();
return retVal;
}
catch(Exception ex) { Console.WriteLine(ex.ToString()); return -1; }
}
----------------------------------------------
whenever i tried to execute this code .. i got following error....
System.FormatException: Input string was not in a correct format.
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.Int32.Parse(String s)
at InventoryControl.cMemo.getNumUnReadMemos() in d:\shirtuniverse\inventorycontrol\cmemo.cs:line 380
------------------------
any idea(s)... y i am getting this error
THANX in advance
|
|
|
|
|
ronin1770 wrote:
CREATE PROCEDURE spNumOfUnReadMemos
@EmpTo char(6), @NumOfUnReadMemos int OUTPUT
AS
SELECT COUNT(EmpTo) FROM tblMemoManagement WHERE
EmpTo=@EmpTo AND ReadYesNo='NO'
RETURN;
GO
No where in this stored procedure is the @NumOfUnReadMemos assigned so the output parameter will not contain anything.
You have two choices.
1. Assign the value to the output parameter
2. Access the Stored Procedure in .NET using ExecuteScalar()
ronin1770 wrote:
//retVal = int.Parse(cmdMemo.Parameters[1].Value.ToString());
I'm guessing that this is where the parser error occurred. The reason is that the value, when converted to a string, is not a number, so the parser throws an exception. It isn't a number because the stored procedure never assigned anything to the output parameter.
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
|
Hi,
I can't seem to hide my MainForm at my application startup. I just want the notifyicon in the systray to be visible. mainform.Hide() dosn't work. It displays the mainform anyway.
Does somebody now a way to do this?
Andreas Färnstrand
|
|
|
|
|
This could work for you:
- set ShowInTaskbar to false
- set WindowState to FormWindowState.Minimized
|
|
|
|
|
And/or set Opacity to 0.
These all seem like kludges, though. It seems like there should be a way to tweak the create params.
Matt Gerrans
|
|
|
|
|
Setting Opacity to 0 is
My two line suggestion should be the easiest possible way of doing it.
You can override the CreateParams property like this:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
return cp;
}
}
I never actually overriden this property before. You can give it a try.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
That doesn't quite work by itself (I replaced "// change" with "cp.Style = cp.Style & ~1;"); you still see the window flash for a fraction of a second on startup.
Matt Gerrans
|
|
|
|