-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
39 lines (32 loc) · 771 Bytes
/
client.cpp
File metadata and controls
39 lines (32 loc) · 771 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 <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <string.h>
#include <string>
using namespace std;
int main()
{
int client_fd = socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in serv;
bzero(&serv, sizeof(serv));
serv.sin_family=AF_INET;
serv.sin_port=htons(8080);
inet_aton("127.0.0.1", &(serv.sin_addr));
connect(client_fd, (sockaddr*)(&serv), sizeof(serv));
int n, m;
char data[256];
char recvd[256];
while (1) {
fgets(data, 256, stdin);
n = strlen(data);
while(n > 0) {
m = write(client_fd, data, n);
n = n - m;
}
n = read(client_fd, recvd, 100);
string resp(recvd);
cout << "package server response is " << resp << endl;
}
}