Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #pragma comment( lib, "ws2_32" )
  2. #include <WinSock2.h>
  3. #include <assert.h>
  4. #include <tchar.h>
  5. #include "easywsclient\easywsclient.hpp"
  6.  
  7. using easywsclient::WebSocket;
  8. static WebSocket::pointer ws = 0;
  9.  
  10. void handle_message(const std::string & message)
  11. {
  12.     printf(">>> %s\n", message.c_str());
  13.  
  14.     if(strstr(message.c_str(), "PING :tmi.twitch.tv")) //Ping message
  15.     {
  16.         ws->send("PONG :tmi.twitch.tv");
  17.         printf("Pong!\n");
  18.     }
  19. }
  20.  
  21. int _tmain(int argc, _TCHAR* argv[])
  22. {
  23.     INT rc;
  24.     WSADATA wsaData;
  25.  
  26.     rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
  27.     if (rc) {
  28.         printf("WSAStartup Failed.\n");
  29.         return 1;
  30.     }
  31.  
  32.     ws = WebSocket::from_url("ws://irc-ws.chat.twitch.tv:80");
  33.     assert(ws);
  34.     ws->send("NICK justinfan234621");
  35.     ws->send("JOIN #fluffyquack");
  36.     while (ws->getReadyState() != WebSocket::CLOSED) {
  37.       ws->poll();
  38.       ws->dispatch(handle_message);
  39.     }
  40.     delete ws;
  41.     WSACleanup();
  42.     return 1;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement