-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_send_test.cpp
executable file
·95 lines (83 loc) · 3.05 KB
/
image_send_test.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
88
89
90
91
92
93
94
95
#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;
bool stop = false;
UDPSocket sockobj;
bool meh = sockobj.initializeSocket(myPort);
cout << "MY IP" << sockobj.getMachineIP() << endl;
int j = 0;
int i = 0;
while(!stop)
{
cin >> input;
if(input == "q")
stop=true;
ifstream fin("trial.jpg",ios::binary);
string extract = string(istreambuf_iterator<char>(fin), istreambuf_iterator<char>());
extract = base64_encode(reinterpret_cast<const unsigned char*>(reinterpret_cast<const unsigned char*> (extract.c_str())), extract.size() + 1);
char * str = new char[extract.size()];
strcpy(str, extract.c_str());
//extract = input;
Message *m =new Message(Request, 1, 3, sockobj.getMyIP(), sockobj.getMyPort(), destIP, destPort, ++i, 8, extract.size(), str);
sockobj.sendMessage(m);
cout << "message of size " << m->getMessageSize() << " sent to " << destIP << endl;
}
// while(!stop && input != "q")
// {
// cin >> input;
// char * str = new char[input.size()];
// strcpy(str, input.c_str());
// Message *m =new Message(Request, 1, 3, "10.1", "10.2", 6666, 9, 8, input.size(), str);
// int stat = pass(m);
// //c.setTimeout(0, 10000);
// c.Send(m);
// }
// Client c(ip,port);
// c.setTimeout(0, 10000);
// string input = "";
//while(!stop)
// {
// cout << "Client main: before send" << endl;
// cin >> input;
// char * str = new char[input.size()];
// strcpy(str, input.c_str());
// Message * m;
// int status = c.Send(m);
// cout << "Client main: after send" << endl;
// }
// Message *m =new Message(Request, 1, 3, "10.1", "10.2", 6666, 9, 8, 10, "MEEEEEEEEH");
// char * s = new char [1024];
// s = m->marshal();
// Message newM(s);
// cout << newM.getMessageType()<< endl;
// cout << newM.getFragmentCount()<< endl;
// cout << newM.getFragmentTotal()<< endl;
// cout << newM.getSourceIP()<< endl;
// cout << newM.getDestinationIP()<< endl;
// cout << newM.getPort()<< endl;
// cout << newM.getRPCId()<< endl;
// cout << newM.getOperation()<< endl;
// cout << newM.getMessageSize()<< endl;
// cout << newM.getMessage()<< endl;
// bool stop = false;
// Message *m =new Message(Request, 1, 3, "10.1", "10.2", 6666, 9, 8, 10, "MEEEEEEEEH");
// // pass(m);
// cout<<"I am out"<<endl;
// cout << "Client main: before send" << endl;
// cin >> input;
// // char * str = new char[input.size()];
// // strcpy(str, input.c_str());
// cout<<"I am here";
// int status = c.Send(m);
// cout << "Client main: after send" << endl;
return 0;
}