// Client side C/C++ program to demonstrate Socket programming #include #include #include #include #include #include #include #define PORT 8080 int main(int argc, char const *argv[]) { struct sockaddr_in address; int sock = 0, message_recieved; struct sockaddr_in serv_addr; char buffer[1024]; FILE *avatar; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("\n Socket creation error \n"); return -1; } memset(&serv_addr, '0', sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(PORT); // Convert IPv4 and IPv6 addresses from text to binary form if (inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr) <= 0) { printf("\nInvalid address/ Address not supported \n"); return -1; } if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { printf("\nConnection Failed \n"); return -1; } avatar = fopen("package.mp4", "a+"); if (avatar == NULL) { printf("Nie udalo się otworzyć pliku"); return -1; } while (1) { message_recieved = recv(sock, buffer, sizeof(buffer), 0); if (strcmp(buffer, "over") == 0) { fclose(avatar); break; } else { fwrite(buffer, sizeof(char), sizeof(buffer), avatar); } printf("%s", "Received"); } return 0; }