View previous topic :: View next topic |
Author |
Message |
Baaleos
Joined: 02 Sep 2007 Posts: 830
|
Posted: Fri Sep 11, 2009 23:09 Post subject: Non-NWNX Development Question |
|
|
Hi guys,
I've just finished a 5 day training course on vs2008 and vs2010 (c#)
I found it quite informative, but found that I am bit stumped on how to feed data into a List<TcpClient> constructor.
Code: |
class ClientList
{
private List<TcpClient> clientlist;
public List<TcpClient> lClientList
{
get
{
return clientlist;
}
set
{
}
}
}
|
in normal instances of using the set { } part, I thought it was a simple case of saying
[code]
set
{
privatevarname = value;
}
[code]
however, this gets read as an error in this instance.
Because this is a list constructor, I thought it would be along the lines of
[code]
set
{
clientlist.add(value);
}
eg - the value would be along the lines of a tcpClient object.
Note - this app I am making, is a simple client/server chat program.
The reason I need a list or array of TCPClients, when they connect, is so they can be sent the chat messages received by the server.
(already made a simple nwn server query program that gets server status etc)
Anyone with c# experience know how I should go about this? |
|
Back to top |
|
|
Zebranky
Joined: 04 Jun 2006 Posts: 415
|
Posted: Sat Sep 12, 2009 0:01 Post subject: |
|
|
What syntax are you trying to use to set the value of the property? Something like:
Code: | foo.lClientList = someclient; |
doesn't make sense intuitively, unless you're trying to say "someclient is now the ONLY client in lClientList". I'm not sure you actually want to use a property -- you might be complicating things that way. Basically, I'm not sure what you're trying to do, and I need more context to give you a sane answer. _________________ Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/
<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.
<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for? |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Sep 12, 2009 0:36 Post subject: |
|
|
your constructor has the same name (exactly) as your class.
Code: | class MyClass
{
private List<MyType> MyList;
public MyClass()
{
this.MyList = new List<MyType>();
}
} |
or in the C# simplified mode
Code: | class MyClass
{
private List<MyType> MyList = new List<MyType>();
public MyClass() {}
} |
The above should show you that 'new' is the keyword when instantiating a constructor for a class. (C++ has 'new' or 'gcnew')
NB: if you make MyList public, you get all the dot-point access to the the List class functionality (ie methods and properties)
MyClass.MyList.add(value) etc |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Sep 12, 2009 0:55 Post subject: |
|
|
your first example has clientlist as a 'property' (not a constructor)
private <type> value;
public <type> MyProperty
{ get { return this.value; } }
{ set { this.value = value; } }
so if <type> is a List 'value' within the 'set' has to be a Llist type (not an element of the List)
Cheers
Gryphyn |
|
Back to top |
|
|
Baaleos
Joined: 02 Sep 2007 Posts: 830
|
Posted: Sat Sep 12, 2009 13:45 Post subject: k |
|
|
Well, im not sure if im doing it right, which is why im asking for advice.
Basically, when a client joins the server, I need them to be added to a list of connected clients.
Then, when a message is received by the server, it will do a
foreach () loop, to ensure that the received message is returned to all clients in the list.
I thought I could do this via making a class called ClientList
and making a list property within it.
Eg - on server start - creates a new ClientList();
then in the onClient enter thread, it adds the client or streamwriter class relating to that client, to the list.
Im having some other problems too, relating to static voids etc, but im working through them slowly.
Can someone suggest the correct method of storing a list of clients? |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Sep 12, 2009 14:10 Post subject: |
|
|
for a Plugin?
Have a look at my SQLServer plugin. (NWNX2 & X4 both have it)
It's got a class that I use to store a list of parameters.
It gets created when the plugin loads, then when each parameter is added, a new entry is added. When the SQLCommand is finally executed, the list contains the value for each of the required parameters. The list is then emptied, for the next query.
I'd imagine you'd want something similar.
CREATE on plugin load,
ADD on client enter
REMOVE on client exit
FOREACH on heartbeat (or interval)
DELETE on plugin unload
[Ed.] The bits to look for
//Needed for Binding Storage.
#include "SQLBinding.h"
#include "wx/dynarray.h"
WX_DECLARE_OBJARRAY(SQLBinding, wxArrayBinding);
SQLBinding is a class which is an element of the list (wxArrayBinding)
your TcpClient
class CNWNXSQLServer : public CNWNXBase
{
public:
CNWNXSQLServer();
virtual ~CNWNXSQLServer();
protected:
wxArrayBinding Binding;
...
}
The rest you can follow in-code.
Cheers
Gryphyn
Last edited by Gryphyn on Sat Sep 12, 2009 14:23; edited 1 time in total |
|
Back to top |
|
|
Baaleos
Joined: 02 Sep 2007 Posts: 830
|
Posted: Sat Sep 12, 2009 14:13 Post subject: Lol |
|
|
Sorry, its not for a nwnx plugin. hehe
Im just learning c# and vs2010 - making a chat client/server program.
I've moved on from the client list problem, (still need a solution) now working on the problem of getting chat text to appear in the chatwindow, when being sent from a different thread.
Think i need to use a dispatcher. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Sep 12, 2009 14:28 Post subject: Re: Lol |
|
|
Baaleos wrote: | Sorry, its not for a nwnx plugin. hehe
Im just learning c# and vs2010 - making a chat client/server program.
I've moved on from the client list problem, (still need a solution) now working on the problem of getting chat text to appear in the chatwindow, when being sent from a different thread.
Think i need to use a dispatcher. |
Oh, LOL - vs2008 has a sample that does exactly this. Off the top of my head I can't recall which section it's under. TcpClient class BOL should point the way.
Check out the System.Net namespace. (TcpClient is in System.Net.Sockets)
you might look at the multicast stuff. <more likely where you're headed> |
|
Back to top |
|
|
|