daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int fd = socket(AF_INET,SOCK_STREAM,0);
  2.  
  3. int enable = 1;
  4. int stanje = setcockopt(fd,SOL_SOCKET,SO_REUSEPORT, &enable,sizeof(int));
  5.  
  6.  
  7. struct sockaddr_in sadr, cadr;
  8. sadr.family = AF_INET;
  9. sadr.sin_port = htons(3333);
  10. sadr.sin_addr.s_addr = INADDR_ANY;//localhost
  11.  
  12.  
  13. int bindPort = bind(fd,(struc sockaddr*)&sadr,sizeof(sadr));
  14. if(bindPort < 0)
  15.     perror("NAPAKA");
  16.  
  17. int listenServer = listen(fd,0);
  18.  
  19. int s = sizeof(cadr);
  20. int acceptClient = accept(fd,(struc sockaddr*)&cadr,&s);
  21.  
  22. int bytes = 0;
  23. char buf[DATASIZE];
  24.  
  25. while(1){
  26.     bytes = recv(acceptClient,buf,DATASIZE,MSG_WAITALL);
  27.    
  28.     for(int i = 0; i < DATASIZE; i++)
  29.     {
  30.         printf("%c",buf[i]);
  31.     }
  32.  
  33. }
  34.  
  35. close(acceptClient);
  36. close(fd);
RAW Paste Data
Top