-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathA.txt
executable file
·113 lines (77 loc) · 1.76 KB
/
A.txt
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Client.cpp
*
* Created on: Nov 11, 2015
* Author: waleed
*/
#include "unp.h"
#include <iostream>
#include<cstring>
#include<fstream>
#include <sstream>
#include "Packet.cpp"
using namespace std;
class Client{
int sockfd;
struct sockaddr_in serv_addr;
struct sockaddr_in addr;
int port;
public :Packet *obj;
public: Client(){
port=1000;
obj=new Packet();
}
public: Client(int portno){
port=portno;
obj=new Packet();
}
~Client(){
close(sockfd);
}
public: void initialize(){
sockfd=socket(AF_INET,SOCK_DGRAM,0);
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = port;
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
}
public: void send(int size){
int servlen=sizeof(serv_addr);
int a=sendto(sockfd,obj,sizeof(struct Packet), 0, (struct sockaddr*)&serv_addr ,servlen);
}
public: void recieve(int size)
{
int addrlen=sizeof(addr);
int a=recvfrom(sockfd,obj,sizeof(struct Packet),0, (struct sockaddr*)& addr ,(socklen_t *) & addrlen);
}
public :Packet show(){
//cout<<obj[0].a<<obj[0].b<<obj[0].message<<endl;
return *obj;
}
public :void message(Packet a){
*obj=a;
}
};
int main()
{
cout<<"Initiate Conversation";
Client *myClient=new Client();
(*myClient).initialize();
Packet *obj=new Packet();
for(int i=0;i<100;i++){
(*obj).message[i];
}
(*myClient).message(*obj);
(*myClient).send(50); //inititate conversation
int count=0;
while(1)
{
// count++;
(*myClient).recieve(50);
//cout<<"Server Send:"<<(*myClient).obj->message<<(*myClient).obj->port<<(*myClient).obj->file<<(*myClient).obj->chunk<<endl;
int pid=fork();
if(pid!=0)
{
int port=(*myClient).obj->port;
int chunk=(*myClient).obj->chunk;
string filename="";
filename="Client/";