Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <netdb.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include <stdio.h>
  11. #include <arpa/inet.h>
  12.  
  13. int main() {
  14.     int connection_socket_descriptor;
  15.     int b;
  16.     char buf;
  17.     char alf[26]="qwertyuioplkjhgfdsazxcvbnm";
  18.     struct sockaddr_in server_address;
  19.    
  20.     //connection_socket_descriptor = socket(AF_INET, SOCK_STREAM, 0);
  21.    
  22.     memset(&server_address, 0, sizeof(server_address));
  23.     server_address.sin_family = AF_INET;
  24.     inet_pton(AF_INET, "150.254.32.68", &(server_address.sin_addr));
  25.     server_address.sin_port = htons(1235);
  26.     /* ZAD1
  27.     connect(connection_socket_descriptor, (struct sockaddr*)&server_address, sizeof(server_address));
  28.     while(1)
  29.     for(int i=0; i<100; i++)
  30.     {
  31.         //sleep(1);
  32.         b = write(connection_socket_descriptor, buf, 100);
  33.         //read(connection_socket_descriptor, buf, 100);
  34.         printf("%d, taki duży bufor: %d\n", i, b);  
  35.        
  36.     }
  37.    
  38.     close(connection_socket_descriptor);*/
  39.     while(1)
  40.     for(int i=0; i<26; i++)
  41.     {
  42.         sleep(1);
  43.         connection_socket_descriptor = socket(AF_INET, SOCK_STREAM, 0);
  44.         connect(connection_socket_descriptor, (struct sockaddr*)&server_address, sizeof(server_address));
  45.         buf = alf[i];
  46.         b = write(connection_socket_descriptor, &buf, 1);
  47.         //read(connection_socket_descriptor, buf, 100);
  48.         printf("Wysłane: %d\n", b);  
  49.         close(connection_socket_descriptor);
  50.     }
  51.    
  52.         return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement