Advertisement
Guest User

kill me

a guest
Oct 24th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.40 KB | None | 0 0
  1. /*
  2. SERVER THINGS
  3. -------------
  4. a place to put various things that either need to be done or explained
  5.  
  6. TO DO:
  7. ------
  8. 1.Write an interpreter for my tcp protocol
  9. 2.Make it do things based on the results of the interpreter
  10. 3.Open VS and give this program a cute icon
  11.  
  12. NOTES:
  13. -----
  14. do the woom
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <winsock2.h>
  20. #include <ws2tcpip.h>
  21.  
  22. #pragma comment(lib, "Ws2_32.lib")
  23.  
  24.  
  25.  
  26. int main() {
  27.     WSADATA wsa;
  28.     int temp_result, server_size;
  29.     SOCKET s, clientsock;
  30.     struct sockaddr_in server, client;
  31.    
  32.     temp_result = WSAStartup(MAKEWORD(2,2), &wsa);
  33.     if (temp_result != 0) {
  34.         printf("aaa wsa died - %i", WSAGetLastError()); //help pls :c
  35.         return 1;
  36.     };
  37.    
  38.     if ((s = socket(AF_INET, SOCK_STREAM, 0)) == SOCKET_ERROR) {
  39.         printf("socket is rip - %i", WSAGetLastError()); //save me
  40.         return 2;
  41.     };
  42.    
  43.     server.sin_addr.s_addr = INADDR_ANY;
  44.     server.sin_family = AF_INET;
  45.     server.sin_port = htons(2127);
  46.    
  47.     if (bind(s, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR) {
  48.         printf("mome help me - %i", WSAGetLastError()); //asdaw
  49.         return 3;
  50.     };
  51.    
  52.     listen(s,3);
  53.    
  54.     server_size = sizeof(server); //kind of ugly variable made out of necessity
  55.    
  56.     int filesending = 0;
  57.     int filesize = 0;
  58.     int bytessent = 0;
  59.     char *rawfile;
  60.    
  61.     while ((clientsock = accept(s, (struct sockaddr *)&client, &server_size)) != INVALID_SOCKET) {
  62.         char stream[2048];
  63.         temp_result = recv(clientsock, stream, 2048, 0);
  64.         if (temp_result < 1) {
  65.             printf("help game is dead %i %i", temp_result, WSAGetLastError());
  66.             return 4;
  67.         };
  68.         //first figure out what the fuck it is
  69.         if (stream[0] == '!') {
  70.             filesending = 1;
  71.             //first find length of the total file
  72.             int length = 0;
  73.    
  74.             for(int i = 0; i < 4; i++) {
  75.                 int num_part = 0;
  76.                 num_part = (int)stream[i + 1];
  77.                 num_part = num_part << 8*(3-i);
  78.                 length = length | num_part;
  79.             };
  80.             filesize = length;
  81.             printf("%i", length);          
  82.             rawfile = (char*) realloc(rawfile, length);
  83.        
  84.         };
  85.        
  86.        
  87.         temp_result = send(clientsock,(const char *)stream, 2048, 0);
  88.         if (temp_result == SOCKET_ERROR) {
  89.             printf("help i need somebody help not just anybody help i need someone, help %i", WSAGetLastError()); //damn it dad this is your fault
  90.             return 5;
  91.         };
  92.     };
  93.    
  94.     closesocket(s);
  95.     WSACleanup();
  96.    
  97.     return 0;
  98. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement