-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp2.cpp
42 lines (38 loc) · 886 Bytes
/
app2.cpp
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
40
41
42
#include <iostream>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <thread>
using namespace std;
int main(int argc, char *argv[]) {
constexpr int socket_family = 41;
constexpr int socket_type = 2;
constexpr int socket_protocol = 2;
constexpr int maxlen = 60;
int sock_id = socket(socket_family, socket_type, socket_protocol);
if (sock_id < 0) return 0;
char msg[maxlen+1];
memset(msg, 0, sizeof(msg));
int k = 0;
while(k < 5) {
int err = recv(sock_id, msg, maxlen, 0);
if (err != -1) {
cout << msg << '\n';
++*msg;
char c = *msg;
if (!('a' <= c && c <= 'z'))
*msg = 'a';
send(sock_id, msg, strlen(msg) + 1, 0);
k = 0;
} else {
++k;
cout << "app2: err is -1, now k = " << k << endl;
}
}
return 0;
}