-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.cpp
88 lines (64 loc) · 1.74 KB
/
server.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "server.hpp"
//Encryption mods
#define Default 0
#define ECB 1
#define CBC 2
#define OFB 3
#define CFB 4
#define CTR 5
using namespace std;
Server::Server(int portnumber)
{
port=portnumber;
sockfd=socket(AF_INET, SOCK_STREAM, 0);
if (sockfd==-1)
cout<<"soket acilmadi";
else
cout<<"soket acildi\n";
SunucuBilgileri.sin_family=AF_INET;
SunucuBilgileri.sin_addr.s_addr=htonl(INADDR_ANY);
SunucuBilgileri.sin_port = htons(port);
int kontrol=bind(sockfd,(struct sockaddr *)&SunucuBilgileri,sizeof(SunucuBilgileri));
if (kontrol<0)
cout<<"IP ADRES KONTROL ET" ;
else
cout<<"SOKET OK\n" ;
};
void Server::Listen()
{
listen(sockfd,5);
clientlength=sizeof(MusteriBilgileri);
clifd=accept(sockfd,(struct sockaddr*)&MusteriBilgileri,&clientlength);
if (clifd==-1)
cout<<"Baglantı Kabul Edilmedi";
else
cout<<"Bağlantı Kabul Edildi\n";
};
void Server::sendMessage()
{
unsigned char chipherText[50];
crypto.AesEncryption(key, 128, plainText, chipherText, 50, ECB); // Encryption with CBC
int mesaj_yazildi = write(clifd, chipherText, sizeof(chipherText));
cout<<"log send message lend : \n" << mesaj_yazildi <<endl;
if(mesaj_yazildi<0)
cout<<"MESAJ YAZILAMADI";
};
void Server::receiveMessage()
{
unsigned char metin[1024]="\n";
unsigned char metin2[1024];
int mesaj_okundu=read(clifd,metin,1024);
crypto.AesDecryption(key, 128, metin, metin2, 50, ECB); // Encryption with CBC
if(mesaj_okundu<0)
cout<<"MESAJ OKUNAMADI";
cout<<"Gelen Metin(ECB):"<< endl << metin2<< endl;
};
int main()
{
Server server(5000);
server.Listen();
for(;;)
{
server.receiveMessage();
}
}