Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. #include <SFML/System.hpp>
  2. #include <iostream>
  3. #include <process.h>
  4. #include <conio.h>
  5. #include <Winsock2.h>
  6. #include "err_enums.h"
  7. #define DEBUG
  8. #include "lib.h"
  9.  
  10. #define PORT 8118
  11. #define MAX 16
  12.  
  13. /*
  14.    some foresight for myself: is it really "safe"
  15.    to find new connections on the same port that
  16.    i will be using to communicate with the clients
  17.    in other threads? will the protocol difference
  18.    prove to work in my favour for once?
  19.  
  20.    at least if it is an issue, it won't affect the
  21.    client, because it only uses one protocol at a
  22.    time (and doesn't need to handle multiple servers
  23.    at one time). not that it makes a big difference,
  24.    a client without a functioning server is about as
  25.    useful as a brick.
  26.    
  27.    actually, the brick is more useful. at least it
  28.    was surfaced as to where it could be used for
  29.    construction, and has value.
  30.  
  31.    does a programme have value? if i've learned an-
  32.    ything about software, it certainly does; and it
  33.    isn't exactly cheap, either. but that is only in
  34.    the case of which the programme is functional and
  35.    is useful. so does a nonfunctioning programme even
  36.    have a value?
  37.  
  38.    well, in theory, a programme's value can be deter-
  39.    mines by taking how long it took to make it and
  40.    taking that in proportion to it's usefulness. so,
  41.    if these two values are proportional, does this
  42.    mean that, despite the time it takes to make the
  43.    programme, if it is nonfunctional, it is without
  44.    value? can there exist something without value?
  45.  
  46.    then again, no one's going to pay for a programme
  47.    that doesn't even compile, or has runtime errors.
  48.    so i suppose a programme's worth cannot be deter-
  49.    mined by these values alone.
  50.  
  51.    so, because everything at least has some sort of
  52.    value and a nonfunctional programme does not, we
  53.    can come to the conclusion that there exists na-
  54.    ught to which has a lesser value than a nonfunc-
  55.    tional programme.
  56.  
  57.    what the hell am i even doing this isn't an essay
  58.    alec get back to work god damnit
  59. */
  60.  
  61. struct User {
  62.     char *username;
  63.     char *ip;
  64.     long long x, y;
  65. };
  66.  
  67. void hClient(void *params); // client handle
  68. void careAboutTheUser(void *params); // gets input from cmd line in new thread
  69.  
  70. int main() {
  71.     SOCKADDR_IN saddr;
  72.     SOCKET s;
  73.     WSADATA w;
  74.     if(WSAStartup(MAKEWORD(2,2), &w) != 0)
  75.         return FAILSTRT;
  76.     s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  77.     if(s == INVALID_SOCKET) {
  78.         WSACleanup();
  79.         return COULD_NOT_SOCKET_CORRECTLY;
  80.     }
  81.     saddr.sin_family = AF_INET;
  82.     saddr.sin_port = htons(PORT);
  83.     saddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
  84.     if(bind(s, (SOCKADDR *)&saddr, sizeof(saddr)) == SOCKET_ERROR) {
  85.         closesocket(s);
  86.         WSACleanup();
  87.         return FAILBIND;
  88.     }
  89.     if(listen(s, 5) == SOCKET_ERROR) {
  90.         closesocket(s);
  91.         WSACleanup();
  92.         return FAILLSTN;
  93.     }
  94.     while(true) {
  95.  
  96.     }
  97.     return OK;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement