class problems, user events
Ok, im making a few classes here bundled up in a dll with a name "ffnet" smacked on it...
The classes are:
netsock //wraps winsock
netserver //a server class for handling the sever and clients
netclient //a client class for handling a single client
ok now, in netserver, i have a function that is supposed to be called in a loop, CheckConnections(). This function checks to see if any clients are trying to connect to the server. If a client is trying to connect to the server, I want this function to call a "user-defined" function. In otherwords, I am going to be calling OnConnectionRequest, a user defined function, or i guess you could call it "Event".
Im not sure if this is called a "function pointer" or a "callback" or if they are the same thing. I dont know, but I would love to know how to do it, so i can continue programming!
OnConnectionRequest has no parameters, but other functions do, so if you would be so kind to show me how to do anoter user event WITH parameters too, i would be happy as could be.
Thanks,
--Fireking
Owner/Leader
Genetics 3rd Dimension Development
this had me awhile ago here ya go
type (*functionname)(parameters)
i.e
int (*pAdd)(int, int)
int Add (int a, int b)
{
return a+b;
}
pAdd = Add;
to call it:
res = (*pAdd)(1,3);
or like a regular function in C++:
res = pAdd (1,3);
you can make a typedef like i do. i use the return type, then the parameters...
typedef void* (*PVOID_VOID) (void);
typedef int (*INT_INT_INT) (int, int , int);
i love these things. Hope this helps you, and i hope i got it right!
quote:Original post by Grizwald
this had me awhile ago here ya go
type (*functionname)(parameters)
i.e
int (*pAdd)(int, int)
int Add (int a, int b)
{
return a+b;
}
pAdd = Add;
to call it:
res = (*pAdd)(1,3);
or like a regular function in C++:
res = pAdd (1,3);
you can make a typedef like i do. i use the return type, then the parameters...
typedef void* (*PVOID_VOID) (void);
typedef int (*INT_INT_INT) (int, int , int);
i love these things. Hope this helps you, and i hope i got it right!
so uh, like this??
class mycoolioclass{public: void CheckConnections(); void (*OnConnectionRequest);//there are no parameters for this}//...in the definitionvoid mycoolioclass::CheckConnection(){ //..crap crap crap OnConnectionRequest();}
btw, what is "res", you never defined it
--Fireking
Owner/Leader
Genetics 3rd Dimension Development
haha...res is just short for result, or whatever is returned. you have to put an arguement list on it, even if you don''t use them...so turn your
void (*OnConnectionRequest);
into
void (*OnConnectionRequest)();//
understand now? :D
void (*OnConnectionRequest);
into
void (*OnConnectionRequest)();//
understand now? :D
OH MY GOD THIS RULES!!!!!!!!!
thanks!
--Fireking
Owner/Leader
Genetics 3rd Dimension Development
thanks!
--Fireking
Owner/Leader
Genetics 3rd Dimension Development
I would suggest making your OnConnect function pure virtual.
That way, all a use would have to do is inherit from you netserver class and provide the implimentations of all your user defined "events"
That way, all a use would have to do is inherit from you netserver class and provide the implimentations of all your user defined "events"
quote:Original post by daerid
I would suggest making your OnConnect function pure virtual.
That way, all a use would have to do is inherit from you netserver class and provide the implimentations of all your user defined "events"
the user''s gotta provide the definition, that way they know when a message actually gets there instead of having to check. All the user has to do is call update in a loop, then if a message is recieved, ClientMessage(int client,char *buffer,int size) is called, which they define. They can process the messages there.
im having trouble with something though, i have finished netserver and it works and its great. But now im programming netclient, and i cannot figure out when the server actually accepts the connection, ie: the client is definately connected.
do you know how?
--Fireking
Owner/Leader
Genetics 3rd Dimension Development
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement