Advertisement
Geralt1001

Untitled

Feb 13th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1.     int newfd;
  2.    
  3.     sin_size = sizeof( my_addr );
  4.    
  5.     while(1)
  6.     {
  7.  
  8.         struct sockaddr_in their_addr;
  9.         bzero( & their_addr, sizeof( their_addr ) );
  10.         if((newfd= accept(sockfd,( struct sockaddr *) &their_addr, &sin_size))==-1)
  11.         {
  12.             printf( "Error - accept\n" );                               //wylaczona notyfikacja, poniewaz polaczenia nie sa blokujace i bylby niezly span na ekranie
  13.             continue;
  14.         }
  15.         printf("And we have a client from:  %s\n",inet_ntoa(their_addr.sin_addr));
  16.         sleep(5);
  17.         if(send(sockfd,"witaj kliencie\n",15,0)==-1)
  18.         {
  19.             printf("Error - send\n");
  20.         }
  21.         else
  22.             printf("podobno wyslano\n");
  23.     }
  24.  
  25.  
  26.  
  27. ///////////////////////////////////////////////////////////////////////////////////////
  28.  
  29.     while( recv(sockfd,buf,sizeof(buf),0)> 1 )
  30.     {
  31.         printf("serwer mowi:\"%s\"\n",buf);
  32.         break;
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement