Wt examples
3.7.1
|
A simple chat server. More...
#include <SimpleChatServer.h>
Classes | |
class | Client |
struct | ClientInfo |
Public Types | |
typedef std::set< Wt::WString > | UserSet |
Typedef for a collection of user names. More... | |
Public Member Functions | |
SimpleChatServer (Wt::WServer &server) | |
Create a new chat server. More... | |
bool | connect (Client *client, const ChatEventCallback &handleEvent) |
Connects to the chat server. More... | |
bool | disconnect (Client *client) |
Disconnect from the chat server. More... | |
bool | login (const Wt::WString &user) |
Try to login with given user name. More... | |
void | logout (const Wt::WString &user) |
Logout from the server. More... | |
bool | changeName (const Wt::WString &user, const Wt::WString &newUser) |
Changes the name. More... | |
Wt::WString | suggestGuest () |
Get a suggestion for a guest user name. More... | |
void | sendMessage (const Wt::WString &user, const Wt::WString &message) |
Send a message on behalve of a user. More... | |
UserSet | users () |
Get the users currently logged in. More... | |
Private Types | |
typedef std::map< Client *, ClientInfo > | ClientMap |
Private Member Functions | |
void | postChatEvent (const ChatEvent &event) |
Private Attributes | |
Wt::WServer & | server_ |
boost::recursive_mutex | mutex_ |
ClientMap | clients_ |
UserSet | users_ |
A simple chat server.
Definition at line 85 of file SimpleChatServer.h.
|
private |
Definition at line 152 of file SimpleChatServer.h.
typedef std::set<Wt::WString> SimpleChatServer::UserSet |
Typedef for a collection of user names.
Definition at line 140 of file SimpleChatServer.h.
SimpleChatServer::SimpleChatServer | ( | Wt::WServer & | server | ) |
bool SimpleChatServer::changeName | ( | const Wt::WString & | user, |
const Wt::WString & | newUser | ||
) |
Changes the name.
Definition at line 113 of file SimpleChatServer.C.
bool SimpleChatServer::connect | ( | Client * | client, |
const ChatEventCallback & | handleEvent | ||
) |
Connects to the chat server.
The passed callback method is posted to when a new chat event is received.
Returns whether the client has been connected (or false if the client was already connected).
Definition at line 61 of file SimpleChatServer.C.
bool SimpleChatServer::disconnect | ( | Client * | client | ) |
Disconnect from the chat server.
Returns whether the client has been disconnected (or false if the client was not connected).
Definition at line 79 of file SimpleChatServer.C.
bool SimpleChatServer::login | ( | const Wt::WString & | user | ) |
Try to login with given user name.
Returns false if the login was not successful.
Definition at line 86 of file SimpleChatServer.C.
void SimpleChatServer::logout | ( | const Wt::WString & | user | ) |
Logout from the server.
Definition at line 100 of file SimpleChatServer.C.
|
private |
Definition at line 154 of file SimpleChatServer.C.
void SimpleChatServer::sendMessage | ( | const Wt::WString & | user, |
const Wt::WString & | message | ||
) |
Send a message on behalve of a user.
Definition at line 149 of file SimpleChatServer.C.
WString SimpleChatServer::suggestGuest | ( | ) |
SimpleChatServer::UserSet SimpleChatServer::users | ( | ) |
Get the users currently logged in.
Definition at line 180 of file SimpleChatServer.C.
|
private |
Definition at line 156 of file SimpleChatServer.h.
|
private |
Definition at line 155 of file SimpleChatServer.h.
|
private |
Definition at line 154 of file SimpleChatServer.h.
|
private |
Definition at line 157 of file SimpleChatServer.h.