#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define PORT 3490 // the port client will be connecting to
#include "generate.h"
int main(int argc, char *argv[])
{
int sockfd, numbytes,len,i;
struct sockaddr_in srvr_addr; // server address information
FILE *fp=fopen("1.mfcc","r");
char becc;
unsigned short aecc;
bool g[9]={1,0,0,0,0,0,1,1,1};// g(x)=x^8 + x^2 + x + 1
Cyclic cd(8,9,g);
cd.tableGenerator();
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}
srvr_addr.sin_family = AF_INET; // host byte order
srvr_addr.sin_port = htons(PORT); // short, network byte order
srvr_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(&(srvr_addr.sin_zero),'\0', 8); // zero the rest of the struct
if (connect(sockfd, (struct sockaddr *)&srvr_addr,
sizeof(struct sockaddr)) == -1) {
perror("connect");
exit(1);
}
while(!feof(fp)){
//bzero(buf,sizeof(buf));
fread(becc,sizeof(char),1,fp);
aecc=cd.tableRead(becc);
send(sockfd,aecc,2);
}
printf("File sent.\n");
close(sockfd);
fclose(fp);
return 0;
}