-
Re: Lacewing Build #19
I've got yet another question:
How do I start a new thread in the new Lacewing? In build #17 I had a line:
Code:
Lacewing::Utility::StartThread(ping, &Server);
And what's the difference between starting a thread in Lacewing and starting a thread in C/C++?
-
Re: Lacewing Build #19
The thread functionality is a class now:
Code:
Lacewing::Thread MyThread ("Some Name", YourThreadFunction);
MyThread.Start (SomeParameter);
The difference is that C/C++ has no facility for starting threads. Lacewing uses whatever functionality is provided by the operating system (WINAPI, or pthread on Unix).
I hope you're aware that most of the liblacewing classes aren't thread safe! Maybe you should consider using something like Lacewing::Timer (if possible) rather than a thread. Failing that, use the EventPump Post() method to run code at a safe time in Lacewing's event loop.
-
Re: Lacewing Build #19
Thanks for the quick reply, as always :D
I had no idea, thanks for letting me know :) You mean something like this?
Code:
void onTick (Lacewing::Timer &Timer)
{
//Ping all clients
}
Lacewing::EventPump TimerPump;
Lacewing::Timer Timer(TimerPump);
Timer.onTick(onTick);
Timer.Start(30000);
To ping each 30 seconds?
-
Re: Lacewing Build #19
Both the Server and the Timer should share the same EventPump, but otherwise, yes.
Did you know that the protocol has pinging built in to detect lost connections?
-
Re: Lacewing Build #19
Really? :D Is that some class I need to use or is pinging done automatically?
-
Re: Lacewing Build #19
It's automatic!
By the way, the correct usage of the EventPump in a console application:
Code:
int main (int argc, char * argv [])
{
Lacewing::EventPump EventPump;
/* Create any classes you want to use, passing EventPump to the constructor. Example: */
Lacewing::RelayServer Server (EventPump);
Server.Host ();
/* This function will not return. Internally, it will loop forever,
letting the other classes know when a socket is ready etc. */
EventPump.StartEventLoop ();
return 0;
}
-
Re: Lacewing Build #19
Wow, that's great! :D Lacewing keeps surprising me :D
And thanks for the code sample :D
Sorry for bothering, but I've got YET another question xD
Could you please give me a sample code on how to iterate through all clients in the server/channel?
-
Re: Lacewing Build #19
No bother at all! :-)
Iterating through all clients on the server:
Code:
for (Lacewing::RelayServer::Client * Client = Server.FirstClient ();
Client; Client = Client->Next ())
{
printf ("Client %s is present\n", Client->Name ());
}
Iterating through all clients on a channel:
Code:
Lacewing::RelayServer::Channel::ClientIterator Iterator (Channel);
for (Lacewing::RelayServer::Client * Client = Iterator.Next ();
Client; Client = Iterator.Next ())
{
printf ("Client %s is in the channel\n", Client->Name ());
}
If you get any "unresolved external symbol" errors with this code, grab the edge liblacewing source from here.
-
Re: Lacewing Build #19
Thanks again! :D I'm sure it's gonna be helpful, not only for me :D
EDIT:
I had the "unresolved external" problem and compiled the source you gave me and it compiled correctly. Do I need to use that *.DLL too?
-
Re: Lacewing Build #19
Sorry for the double post, but it's a different thing now. There seems to be a bug in the Relay Client for MMF. The function "StringWithSize$" takes only one parameter - the index. Shouldn't it also take the size?