Advertisement
WeltEnSTurm

Untitled

Jan 27th, 2012
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1.  
  2. #include "ws/network.hpp"
  3. #include <string>
  4. #include <iostream>
  5.  
  6. namespace test {
  7.  
  8.     using std::string;
  9.     using std::cout;
  10.     using std::endl;
  11.  
  12.     class server: public ws::server {
  13.    
  14.         static void onCookies(const ws::client& from, const server& to, const string& content){
  15.             cout << "Cookies have been baked with " << content << endl;
  16.         }
  17.        
  18.         server(): ws::server {
  19.             bindMessage("Cookies", onCookies);
  20.         }
  21.    
  22.         void onConnect(const ws::client& c){
  23.             cout << c.Address() << endl;
  24.         }
  25.        
  26.         void onMessage(const ws::client& from, const string& name, const string& content){
  27.             cout << "Client " << from.Address() << " sent message \"" << name << "\" with content " << content;
  28.             if(name == "Stop"){
  29.                 cout << "NOOO DON'T KILL ME" << endl;
  30.                 Stop();
  31.             }
  32.         }
  33.        
  34.     };
  35.    
  36. }
  37.  
  38. int main(){
  39.     test::server s(27015);
  40.     s.Start();
  41.     while(s.Running())
  42.         s.Think();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement