Você está na página 1de 1

/*Aluno: Marcus Vinicius P.

Mendes
Faculdade Catolica do Tocantins
Sistemas de Informacao
Programa criado em linguagem C.
Este programa faz a comunicacao entre o cliente e o servidor e gera um arquivo
chamado Total.txt.
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>

main() {

int sock, n;
struct sockaddr_in estacao, servidor;
socklen_t tam = sizeof(servidor);
char msg[25];
sock = socket(AF_INET, SOCK_DGRAM, 0);
bzero(&estacao, sizeof(estacao));
estacao.sin_family = AF_INET;
estacao.sin_addr.s_addr = htonl(INADDR_ANY);
estacao.sin_port = htons(1920);
bind(sock, (struct sockaddr *) &estacao, sizeof(estacao));

n = recvfrom(sock, msg, sizeof(msg), 0, (struct sockaddr


*)&servidor, &tam);
msg[n] = '\0';

printf("\nMensagem recebida do host %s \n",


inet_ntoa(servidor.sin_addr));
printf("\nO arquivo foi geradono com o nome: Total.txt\n\n");
sleep(2);

sendto(sock, "Mensagem do Cliente: O arquivo foi gerado!\0", 45,


0, (struct sockaddr *)&servidor, tam);
//puts(msg);
system(msg);
sleep(1);
close(sock);

Você também pode gostar