ass1
ass1
ass1
h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
FILE *file;
perror("Socket failed");
exit(EXIT_FAILURE);
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(PORT);
perror("Bind failed");
close(server_fd);
exit(EXIT_FAILURE);
if (listen(server_fd, 3) < 0) {
perror("Listen failed");
close(server_fd);
exit(EXIT_FAILURE);
perror("Accept failed");
close(server_fd);
exit(EXIT_FAILURE);
printf("Connection accepted.\n");
if (file == NULL) {
close(new_socket);
close(server_fd);
exit(EXIT_FAILURE);
int bytes_read;
fclose(file);
close(new_socket);
close(server_fd);
exit(EXIT_FAILURE);
fclose(file);
close(new_socket);
close(server_fd);
return 0;