atm959

Client

Mar 17th, 2019
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.66 KB | None | 0 0
  1. #include <coreinit/thread.h>
  2. #include <coreinit/time.h>
  3.  
  4. #include <whb/proc.h>
  5. #include <whb/log.h>
  6. #include <whb/log_console.h>
  7.  
  8. #include <nsysnet/socket.h>
  9.  
  10. #include <string.h>
  11.  
  12. enum {
  13.    PACKET_HEARTBEAT = 1,
  14.    PACKET_PLATFORM
  15. };
  16.  
  17. enum {
  18.    PLATFORMTYPE_WIIU = 1,
  19.    PLATFORMTYPE_WII,
  20.    PLATFORMTYPE_PC
  21. };
  22.  
  23. int sockFD;
  24. struct sockaddr_in sa;
  25. char buffer[1024];
  26.  
  27. int main(int argc, char **argv) {
  28.    WHBProcInit();
  29.    WHBLogConsoleInit();
  30.    WHBLogPrintf("Hello World!");
  31.  
  32.    socket_lib_init();
  33.  
  34.    sockFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  35.  
  36.    memset(&sa, 0, sizeof(sa));
  37.    sa.sin_family = AF_INET;
  38.    sa.sin_port = htons(11000);
  39.    inet_aton("192.168.0.20", &sa.sin_addr);
  40.  
  41.    connect(sockFD, (struct sockaddr *)&sa, sizeof(sa));
  42.  
  43.    while(WHBProcIsRunning()) {
  44.       memset(buffer, 0, sizeof(buffer));
  45.       buffer[0] = PACKET_HEARTBEAT;
  46.       send(sockFD, buffer, 1, 0);
  47.       memset(buffer, 0, sizeof(buffer));
  48.       while(buffer[0] != PACKET_HEARTBEAT){
  49.          recv(sockFD, &buffer, 1, 0);
  50.          WHBLogPrintf("Waiting for heartbeat return...\n");
  51.          
  52.          if(!WHBProcIsRunning()) goto exit;
  53.  
  54.          WHBLogConsoleDraw();
  55.       }
  56.  
  57.       memset(buffer, 0, sizeof(buffer));
  58.       buffer[0] = PACKET_PLATFORM;
  59.       buffer[1] = PLATFORMTYPE_WIIU;
  60.       send(sockFD, buffer, 2, 0);
  61.       WHBLogPrintf("Heartbeat returned.\n");
  62.  
  63.       WHBLogConsoleDraw();
  64.    }
  65.  
  66. exit:
  67.    WHBLogPrintf("Exiting... good bye.");
  68.    WHBLogConsoleDraw();
  69.    OSSleepTicks(OSMillisecondsToTicks(1000));
  70.  
  71.    socketclose(sockFD);
  72.    socket_lib_finish();
  73.  
  74.    WHBLogConsoleFree();
  75.    WHBProcShutdown();
  76.    return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment