-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_receive.cpp
executable file
·52 lines (44 loc) · 1.21 KB
/
image_receive.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
#include "UDPSocket.h"
#include <iostream>
#include <string>
#include<fstream>
using namespace std;
int main(int argc, char ** argv)
{
char * myIP= argv[1];
char * destIP = argv[2];
unsigned int myPort = stoi(argv[3]);
unsigned int destPort = stoi(argv[4]);
string input= "meh";
bool stop = false;
UDPSocket sockobj;
bool meh = sockobj.initializeSocket(myPort);
cout << "MY IP" << sockobj.getMyIP() << endl;;
int i=0;
int j = 0;
string extract;
while(!stop && input != "q")
{
Message * newM = sockobj.receiveMsg();
cout << "Received Msg of size " << newM->getMessageSize() << endl;
if(newM != NULL)
{
int size = newM->getMessageSize();
char *c = new char[size];
c = newM->getMessage();
int i=0;
string img;
while(size--)
img+=c[i++];
img = base64_decode(img);
if(img == "q")
stop = true;
ofstream out;
string path = "out_img" + to_string(j) + ".jpg";
out.open(path, ios_base::out | ios_base::binary);
out << img;
out.close();
}
}
return 0;
}