-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReporter.cpp
60 lines (44 loc) · 1.15 KB
/
Reporter.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
using namespace std;
#define PORT 8080
int main(){
int sockfd;
struct sockaddr_in seraddr;
int option=1;
char buffer[1024] = {0};
int ret;
if((sockfd = socket(AF_INET, SOCK_STREAM,0))<0){
perror("socket failed");
exit(EXIT_FAILURE);
}
if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &option, sizeof(option))){
perror("setsockopt failed");
exit(EXIT_FAILURE);
}
seraddr.sin_family = AF_INET;
seraddr.sin_port = htons(PORT);
if(inet_pton(AF_INET, "127.0.0.1", &seraddr.sin_addr)<=0)
{
perror("Invalid address/ Address not supported ");
exit(EXIT_FAILURE);
}
if (connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr)) < 0)
{
perror("connect Failed");
exit(EXIT_FAILURE);
}
while(1){
string msg;
cout<<"Enter Message:";
getline(cin,msg);
send(sockfd,msg.c_str(),msg.length()+1,0);
//recv(sockfd,buffer,1024,0);
//cout<<"client received:"<<buffer<<endl;
cout<<"Message sent:"<<msg<<endl;
}
return 0;
}