-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSync.cpp
54 lines (41 loc) · 1.13 KB
/
Sync.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
#include "Sync.h"
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <string.h>
#include <iostream>
Sync::Sync(){
}
StatusTypeDef Sync::Connect(){
StatusTypeDef res;
struct protoent *protocol;
struct sockaddr_in serverInfo;
//Obtient le numéro identifiant le protocol TCP
protocol = getprotobyname("TCP");
//Creation de la socket en mode connecté
socketId = socket(AF_INET,SOCK_STREAM, protocol->p_proto);
if(socketId == -1 ){
res = STATUS_ERROR;
}else{
serverInfo.sin_port = htons(3002);
serverInfo.sin_family = AF_INET;
if(inet_aton("127.0.0.1", &(serverInfo.sin_addr)) == 0){
cout << "Adresse IP fausse" << endl;
return STATUS_ERROR;
}
if(connect(socketId, (struct sockaddr *)(&serverInfo), sizeof(sockaddr)) == -1){
res = STATUS_ERROR;
}else{
res = STATUS_OK;
}
}
return(res);
}
void Sync::Close(){
shutdown(socketId, SHUT_RDWR);
}
void Sync::Process(){
}