logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Non-NWNX Development Question

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Fri Sep 11, 2009 23:09    Post subject: Non-NWNX Development Question Reply with quote

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
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Sat Sep 12, 2009 0:01    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Sep 12, 2009 0:36    Post subject: Reply with quote

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
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Sep 12, 2009 0:55    Post subject: Reply with quote

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
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Sep 12, 2009 13:45    Post subject: k Reply with quote

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
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Sep 12, 2009 14:10    Post subject: Reply with quote

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
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Sep 12, 2009 14:13    Post subject: Lol Reply with quote

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
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Sep 12, 2009 14:28    Post subject: Re: Lol Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group