Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/un.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- /* MAIN */
- int main() {
- /* VARS */
- int sock_fd;
- struct sockaddr_in socket_address;
- char buffer[256];
- /* BODY */
- sock_fd = socket(AF_INET, SOCK_STREAM, 0);
- if(sock_fd == -1){
- perror("Errore sys call socket()");
- exit(EXIT_FAILURE);
- }
- socket_address.sin_family = AF_INET;
- socket_address.sin_port = htons(2020);
- socket_address.sin_addr.s_addr = inet_addr("79.52.89.92");
- if(connect(sock_fd, (struct sockaddr*)&socket_address, sizeof(socket_address)) == -1){
- perror("Errore sys call connect()");
- exit(EXIT_FAILURE);
- }
- while(1){
- bzero(buffer, strlen(buffer));
- printf("\nInserisci un numero intero di cui vuoi il quadrato > ");
- fgets(buffer, 255, stdin);
- write(sock_fd, buffer, strlen(buffer));
- if(strncmp(buffer, "end", 3) == 0) break;
- read(sock_fd, buffer, 256);
- printf("%s", buffer);
- }
- close(sock_fd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement