-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
39 lines (35 loc) · 825 Bytes
/
client.c
File metadata and controls
39 lines (35 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <string.h>
#define port 12340
#define buff_size 256
FILE *fp;
int main()
{
char buff[buff_size];
char filename[20];
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in server_address;
server_address.sin_family = AF_INET;
server_address.sin_port = htons(port);
server_address.sin_addr.s_addr = INADDR_ANY;
int connfd = connect(sockfd, (struct sockaddr*) &server_address, sizeof(server_address));
recv(sockfd, filename, sizeof(filename), 0);
printf(filename);
fp = fopen(filename, "r");
if(fp == NULL)
{
perror("fopen");
}
else
{
while (fgets(buff, sizeof(buff), fp)!= NULL)
{
send(sockfd, buff, sizeof(buff), 0);
}
fclose(fp);
}
close(sockfd);
}