Monday, 28 November 2022

cn

 PARITY CHECKER


#include<bits/stdc++.h>

using namespace std;

int parity_check(vector<int> &msg,int n)

{

int count=0;

for(int i=0;i<n;i++)

{

if(msg[i]==1)

{

count++;

}

}

return count;

}

int main()

{

int m,n;

cout<<"Enter total Number of bits: ";

cin>>n;

cout<<"Enter Number of bits:"<<endl;

vector<int> msg;

for(int i=0;i<n;i++)

{

cin>>m;

msg.push_back(m);

}

int a=parity_check(msg,n);

while(1){


int ch;

cout<<"\n\n---------Parity check-----------";

cout<<"\n\n1. Even parity";

cout<<"\n2. Odd Parity";

//cout<<"\n2. Odd Parity";

cout<<"\n\nEnter your choice: ";

cin>>ch;

switch(ch)

{

case 1:

if(a%2==0)

{

msg.push_back(0);

cout<<"\nNo error occurred";

}

else

{

msg.push_back(1);

cout<<"\nError occurred";

}

break;

case 2:

if(a%2!=0)

{

msg.push_back(0);

cout<<"\nNo error occurred";

}

else

{

msg.push_back(1);

cout<<"\nError occurred";

}

case 3:

{

exit(1)

break;

default:

cout<<"\nInvalid choice !!!";

}


}

}

return 0;

}


--------------------------------------------------------------------------------------------------


Hamming code



#include<bits/stdc++.h>

using namespace std;

void hammingCode(vector<int> &msg,int m)

{

int r=1;

while(pow(2,r)< (m+r+1))

{

r++;

}

 vector<int> hc(m+r);

 

 for(int i=0;i<r;++i)

 {

 hc[pow(2,i)-1]=-1;

}

int j=0;

for(int i=0;i<m+r;i++)

{

if(hc[i]!=-1)

{

hc[i]=msg[j];

j++;

}

}

for (int i = 0; i < (r + m); i++) 

{

 if(hc[i] != -1)

 continue;

 int x = log2(i + 1);

 int count = 0;

 for(int j = i + 2;j <= (r + m); ++j) 

{

 if(j & (1 << x)) 

{

 if(hc[j - 1] == 1) 

{

 count++;

 }

 }

 }

 

 

 //even parity

 if(count % 2 == 0) 

{

 hc[i] = 0;

 }

 

 else 

{

 hc[i] = 1;

 }

 }

 

 cout<<"-----------------Message bits---------------\n\n";

 for(int i=0;i<m;i++)

 {

 cout<<msg[i]<<" ";

}

cout<<"\n\n--------------Generated Hamming Code----------------\n";

 for(int i=0;i<hc.size();i++)

 {

 cout<<hc[i]<<" ";

}

 

}

int main()

{

int m;

cout<<"Enter number of message bits: ";

cin>>m;

int a;

vector<int> msg;

for(int i=0;i<m;i++)

{

cin>>a;

msg.push_back(a);

}

hammingCode(msg,m);

return 0;

}



-------------------------------------------------------------------------------------

CRC




#include <iostream>

#include <math.h>

#include <cstring>

using namespace std;

char exor(char a,char b) 

{

if(a==b)

return '0';

else

return '1';

}

void crc(char data[], char key[])

{

int datalen = strlen(data);

int keylen = strlen(key);

for(int i=0;i<keylen-1;i++) 

data[datalen+i]='0';

data[datalen+keylen-1]='\0';

int codelen = datalen+keylen-1; 

char temp[20],rem[20];

for(int i=0;i<keylen;i++)

rem[i]=data[i]; 

for(int j=keylen;j<=codelen;j++)

{

 for(int i=0;i<keylen;i++)

 temp[i]=rem[i]; 

 if(rem[0]=='0') 

 {

 for(int i=0;i<keylen-1;i++)

 rem[i]=temp[i+1];

 }

 else 

 { 

 for(int i=0;i<keylen-1;i++)

 rem[i]=exor(temp[i+1],key[i+1]);

 

 }

 

 if(j!=codelen)

 rem[keylen-1]=data[j]; 

 else

 rem[keylen-1]='\0';

}

 

for(int i=0;i<keylen-1;i++)

data[datalen+i]=rem[i]; 

data[codelen]='\0';

cout<<"CRC="<<rem<<"\nDataword="<<data;

}

int main()

{

char key[20],data[20];

cout<<"Enter the data:";

cin>>data;

cout<<"Enter the key:";

cin>>key;

crc(data,key); 

return 0;

}




-----------------------------------------Flow Control----------------------------------


Go Back and Q



#include <iostream>
#include <list>
#include <vector>
#include <unistd.h>
using namespace std;

class data
{
public:
int sw;
int sf; 
int sn;
int rn;
int ack;
vector<int> sv;
vector<int> rv;
list<int> window;
data()
{
sw = 4;
sf = 0;
sn = 0;
rn = 0;
ack= 0;
}
void sender();
void waitforevent();
void getdata();
void makeframe();
void sendframe();
void showWindow();
void receiver();
};

void data :: receiver()
{
cout<<"********* ON RECEIVER SIDE ************"<<endl;
waitforevent();
cout<<"Received "<<rn<<" frame"<<endl;
rv.push_back(window.front());
rn++;
ack++;
cout<<"Acknowledgement sent for "<<ack<<" frame .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
}


void data :: showWindow()
{
cout<<"Window currently contains : ";
list<int> :: iterator itr = window.begin();
for(itr; itr!=window.end(); itr++)
{
cout<<*itr;
}
cout<<endl;
}

void data :: sendframe()
{
cout<<"Window size is : "<<sw<<endl;
cout<<"Getting "<<sw<<" frames into window"<<endl;
for(int i=0; i<sw; i++)
{
window.push_back(sv.at(i));
}
sf = window.front();
sn = window.back();
showWindow();
cout<<"Sending these "<<sw<<" Frames without waiting for acknowlegement .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
cout<<"Sent successfully ..."<<endl;
for(int i=0; i<sv.size(); i++)
{
receiver();
cout<<"************ SENDER SIDE ****************"<<endl;
waitforevent();
cout<<"Acknowledgement Received ..."<<endl;
cout<<"Removing Acknowledged frame from window .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
window.pop_front();
if(i<(sv.size()-sw))
{
cout<<"Getting next frame into the window ";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
window.push_back(sv.at(i+4));
}
showWindow();
}
}




void data :: makeframe()
{
cout<<"Making Frames";
cout << " .";
sleep(2);
cout << " .";
sleep(2);
cout << " ."<<endl;
}

void data :: getdata()
{
int size;
cout<<"Enter the number of bits you want to send : "<<endl;
cin>>size;
cout<<"Enter the bits : "<<endl;
for(int i=0; i<size; i++)
{
int num;
cin>>num;
sv.push_back(num);
}
}


void data :: waitforevent()
{
cout << "Waiting for event";
sleep(2);
cout << " .";
sleep(2);
cout << " .";
sleep(2);
cout << " ."<<endl;
}

void data :: sender()
{
waitforevent();
getdata();
makeframe();
sendframe();
}


int main()
{
data d;
cout<<"**************** Data Transmission using Go Back N Protocol ***************"<<endl;
d.sender();
cout<<"*************After successfull Transmission***********"<<endl;
cout<<"The message sent by sender is : ";
for(int i=0; i<d.sv.size(); i++)
{
cout<<d.sv.at(i);
}
cout<<endl;
cout<<"The message received by receiver is : ";
for(int i=0; i<d.rv.size(); i++)
{
cout<<d.rv.at(i);
}
cout<<endl;
}




--------------------------------------------------------------------------------------------


Stop and Wait



#include <iostream>
#include <unistd.h>
#include <vector>
using namespace std;

class data
{
public:
int sn;
int rn;
int ack;
int size;
int counter;
vector<int> sv;
vector<int> rv;
bool cansend;

data()
{
sn=0;
rn=0;
ack=0;
size=0;
counter=0;
cansend=true;
}
void sender();
void getdata();
void waitforevent();
void makeframe();
void sendframe();
void receiver(int i);
void result();
};


void data :: result()
{
cout<<"The data sent at sender side is : ";
for(int i=0; i<sv.size(); i++)
{
cout<<sv[i];
}
cout<<endl;
cout<<"The data received at receiver side is : ";
for(int i=0; i<rv.size(); i++)
{
cout<<rv[i];
}
cout<<endl;
}


void data :: receiver(int i)
{
cout<<"************ON RECEIVER SIDE*****************"<<endl;
cout<<"Waiting for an event .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;

    if(counter!=sv.size()/2)
    {
cout<<"Received "<<sn<<" Frame"<<endl;
cout<<" Timer stops"<<endl;
if(sn==rn)
{
cout<<"Extracting data ";
sleep(2);
cout<<" .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
sleep(2);
rv.push_back(i);
rn++;
cout<<"Sending Acknowledgement .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
}

    }

}

void data :: sendframe()
{
int ack1;
cout<<"Sending Frames : "<<endl;
for(int i=0; i<sv.size(); i++)
{
cout<<"Sending "<<sn<<" Frame .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
cout<<" Timer Starts .";
sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
receiver(sv[i]);
if(sn!=(rn-1))
{
            cout<<"************** ON SENDER SIDE ***************"<<endl;
            cout<<"Sender Timed Out "<<endl;
            cout<<"Acknowlegdement NOT received "<<endl;
            cout<<"Retrasmitting the "<<sn<<" Frame again .";
            cout<<" .";
            sleep(2);
            cout<<" ."<<endl;
            counter++;
            cout<<" Timer Starts again .";
            sleep(2);
            cout<<" .";
            sleep(2);
            cout<<" ."<<endl;
            receiver(sv[i]);
            sn++;
}else
{
cout<<"************** ON SENDER SIDE ***************"<<endl;
cout<<"Acknowledgement Received for  "<<rn<<" frame "<<endl;
            sn++;
            counter++;
}

}

cout<<" All frames sent Successfully ..."<<endl;
}


void data :: makeframe()
{
cout<<"Making Frames";
cout << " .";
sleep(2);
cout << " .";
sleep(2);
cout << " ."<<endl;
}

void data :: waitforevent()
{
cout << "Waiting for event";
sleep(2);
cout << " .";
sleep(2);
cout << " .";
sleep(2);
cout << " ."<<endl;
}

void data :: getdata()
{
cout<<"Enter the number of bits you want to send : "<<endl;
cin>>size;
cout<<"Enter the bits : "<<endl;
for(int i=0; i<size; i++)
{
int num;
cin>>num;
sv.push_back(num);
}
}



void data :: sender()
{
waitforevent();
getdata();
makeframe();
sendframe();
}




int main()
{
data d;
d.sender();
d.result();
}



---------------------------------------------------------------------------------------------

SLECTIVE REPEAT


#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
using namespace std;

int n,r;
class frame
{
    public:
    char ack;
    int data;
};


void resendframe(frame frm[])
{
    cout<<"Resending frame "<<r<<" .";
    sleep(2);
cout<<" .";
sleep(2);
cout<<" ."<<endl;
    frm[r].ack='y';
    cout<<"Received frame is : "<<frm[r].data<<endl;

    cout<<"The message received at receiver side is : ";
    for(int i=1; i<=n; i++)
    {
        cout<<frm[i].data;
    }
    cout<<endl;
}

void receiver(frame frm[])
{
    r=n/2;
    frm[r].ack='n';
    for(int i=1; i<=n; i++)
    {
        if(frm[i].ack=='n')
        {
            cout<<"The frame number "<<r<<" is not received "<<endl;
        }
    }
    resendframe(frm);
    
}





int main()
{
    frame frm[10];
    int i;
    cout<<"Enter the number of frames to be sent : "<<endl;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int j;
        cout<<"Enter the frame : "<<endl;
        cin>>j;
        frm[i].data = j;
        frm[i].ack = 'y';
    }
    receiver(frm);

    


}



-------------------------------------------------------Subnet Calculator----------------------------------------------

SUBNET Calculator


#include <iostream>
#include <math.h>
#include <iterator>
#include <vector>
#include <sstream>
using namespace std;

struct change : ctype<char>
{
    const mask* arr()
    {
        static vector<mask> m(classic_table(), classic_table() + table_size);
        m['.'] |= space;
        m['/'] |= space;
        return &m[0];
    }
    change(size_t s = 0) : ctype(arr(), false, s) {}
};

int n(int number)
{
    int num;

    if (number == 1)
        num = 128;
    if (number == 2)
        num = 192;
    if (number == 3)
        num = 224;
    if (number == 4)
        num = 240;
    if (number == 5)
        num = 248;
    if (number == 6)
        num = 252;
    if (number == 7)
        num = 254;

    return num;
}

int main()
{


    string str;
    cout << "Enter an IP address (format: x.x.x.x/y) : ";
    cin >> str;

    istringstream ins(str);

    ins.imbue(locale(ins.getloc(), new change()));
    istream_iterator<long> a(ins), end;
    vector<long> vect(a, end);
    char ch;

    if (vect[0] <= 127)
    {
        ch = 'A';
    }
    else if (vect[0] >= 128 && vect[0] <= 191)
    {
        ch = 'B';
    }
    else if (vect[0] >= 192 && vect[0] <= 223)
    {
        ch = 'C';
    }
    else {
        cout << "error" << '\n';
    }

    cout << "Number of usable Hosts: ";
    int nouh;
    nouh = 32 - vect[4];
    nouh = pow(2, nouh);
    cout << nouh - 2 << '\n';

    int snet;
    int snt;

    snet = vect[4] / 8;
    snt = snet;
    snet = vect[4] - (8 * snet);
    snet = n(snet);

    cout << "Class Type: " << ch << '\n';
    cout << "Subnet Address: ";

    if (snt == 0) {
        cout << snet << ".0.0.0" << '\n';
    }
    else if (snt == 1) {
        cout << "255." << snet << ".0.0" << '\n';
    }
    else if (snt == 2) {
        cout << "255.255." << snet << ".0" << '\n';
    }
    else if (snt == 3) {
        cout << "255.255.255." << snet << '\n';
    }
    else {
        cout << "ERROR!" << '\n';
    }

    int bc;
    int sub = 0;
    int sn = vect[4] / 8;
    sn = vect[4] - (8 * sn);
    sn = n(sn);
    bc = 256 - sn;
    bc = bc + sub - 1;

    cout << "Broadcast Address: ";
    if (vect[4] < 8) {
        cout << bc << ".255.255.255" << '\n';
    }

    if (vect[4] >= 8 && vect[4] < 16) {
        cout << vect[0] << "." << bc << ".255.255" << '\n';
    }

    if (vect[4] >= 16 && vect[4] < 24) {
        cout << vect[0] << "." << vect[1] << "." << bc << ".255" << '\n';
    }

    if (vect[4] >= 24 && vect[4] < 32) {
        cout << vect[0] << "." << vect[1] << "." << vect[2] << "." << bc << '\n';
    }

    return 0;
}

/*
Enter an IP address (format: x.x.x.x/y) : 192.168.10.1/16
Number of usable Hosts: 65534
Class Type: C
Subnet Address: 255.255.0.0
Broadcast Address: 192.168.255.255

--------------------------------
*/



------------------------------LINKSPACE ROUTING----------------------------------

    Links apce vector


#include<iostream>

#include<stdio.h>

using namespace std;

int main()

 

{

 

int count,src_router,i,j,k,w,v,min;

 

int cost_matrix[100][100],dist[100],last[100];

 

int flag[100];

 

cout<<"\n Enter the no of routers";

 

cin>>count;

 

cout<<"\n Enter the cost matrix values:";

 

for(i=0;i<count;i++)

 

 

{

 

for(j=0;j<count;j++)

 

{

 

printf("\n%d->%d:",i,j);

 

scanf("%d",&cost_matrix[i][j]);

 

if(cost_matrix[i][j]<0)cost_matrix[i][j]=1000;

 

}

 

}

 

printf("\n Enter the source router:");

 

scanf("%d",&src_router);

 

for(v=0;v<count;v++)

 

{

 

flag[v]=0;

 

last[v]=src_router;

 

dist[v]=cost_matrix[src_router][v];

 

}

 

flag[src_router]=1;

 

for(i=0;i<count;i++)

 

{

 

min=1000;

 

for(w=0;w<count;w++)

 

{

 

if(!flag[w])

 

if(dist[w]<min)

 

{

 

v=w;

 

min=dist[w];

 

}

 

}

 

flag[v]=1;

 

for(w=0;w<count;w++)

 

{

 

if(!flag[w])

 

if(min+cost_matrix[v][w]<dist[w])

 

{

 

dist[w]=min+cost_matrix[v][w];

 

last[w]=v;

 

}

 

}

 

}

 

for(i=0;i<count;i++)

 

{

 

printf("\n%d==>%d:Path taken:%d",src_router,i,i);

 

w=i;

 

while(w!=src_router)

 

{

 

printf("\n<--%d",last[w]);w=last[w];

 

}

 

printf("\n Shortest path cost:%d",dist[i]);

 

}

 

}



----------------------------------------Distance Vector-------------------------------------------



#include<iostream>

#include<conio.h>

using namespace std;

 

int main()

{

    int graph[50][50];

    int i,j,k,t;

    int nn;

 

    cout<<"\n Enter Number of Nodes:";

    cin>>nn;

 

    /* Initialize graph*/

    for (i=0;i<nn;i++)

    {

        for(j=0;j<nn;j++)

        {

            graph[i][j]=-1;

        }

    }

 

    /* Vertex names */

    char ch[7]={'A','B','C','D','E','F','G'};

 

    /* Get input */

    for (i=0;i<nn;i++)

    {

        for(j=0;j<nn;j++)

        {

            if(i==j)

            {

                graph[i][j]=0;

            }

            if(graph[i][j]==-1)

            {

                cout<<"\n Enter Distance between "<<ch[i]<<" - "<<ch[j]<<" : ";

                cin>>t;

                graph[i][j]=graph[j][i]=t;

            }

        }

    }

 

    /* Initializing via */

    int via[50][50];

    for (i=0;i<nn;i++)

    {

        for(j=0;j<nn;j++)

        {

            via[i][j]=-1;

        }

    }

 

    cout<<"\n After Initialization";

    /* Display table initialization */

    for (i=0;i<nn;i++)

    {

        cout<<"\n"<<ch[i]<<" Table";

 

        cout<<"\nNode\tDist\tVia";

        for(j=0;j<nn;j++)

        {

              cout<<"\n"<<ch[j]<<"\t"<<graph[i][j]<<"\t"<<via[i][j];

        }

    }

 

    //sharing table

    int sh[50][50][50];

    for(i=0;i<nn;i++)

    {

        for(j=0;j<nn;j++)

        {

            for (k=0;k<nn;k++)

            {

                /* Check if edge is present or not*/

                if((graph[i][j]>-1)&&(graph[j][k]>-1))

                {

                    sh[i][j][k]=graph[j][k]+graph[i][j];

                }

                else

                {

                    sh[i][j][k]=-1;

                }

            }

        }

    }

 

    /*displaying shared table */

    for(i=0;i<nn;i++)

    {

        cout<<"\n\n For "<<ch[i];

        for (j=0;j<nn;j++)

        {

            cout<<"\n From "<<ch[j];

            for(k=0;k<nn;k++)

            {

                cout<<"\n "<<ch[k]<<" "<<sh[i][j][k];

            }

        }

    }

    

    /* Updating */

    int final[50][50];

    for(i=0;i<nn;i++)

    {

        for(j=0;j<nn;j++)

        {

            /* Copy initial value from input graph*/

            final[i][j]=graph[i][j];

            via[i][j]=i;

            

            /*Update them*/

            /* Check condition a - b - c */

            for(k=0;k<nn;k++)

            {

                

                if((final[i][j]>sh[i][k][j]) || (final[i][j] == -1))

                {

                    if(sh[i][k][j]>-1)

                    {

                        final[i][j]=sh[i][k][j];

                        via[i][j]=k;

                    }

                }

            }

            /* After considering three vertex if final not found

                consider 4th

                a- b- c- d

            */

 

            if(final[i][j]==-1)

            {

                for(k=0;k<nn;k++)

                {

 

                    if((final[i][k]!=-1)&&(final[k][j]!=-1))

                    {

                        if((final[i][j]==-1) || ((final[i][j]!=-1) &&(final[i][j]>final[i][k]+final[k][j])))

                        {

                            if(final[i][k]+final[k][j]>-1)

                            {

                                final[i][j]=final[i][k]+final[k][j];

                                via[i][j]=k;

                            }

                        }

                    }

                    

                }

            }

        }

    }

 

    cout<<"\n After Update :";

    /* Display table Updation */

    for (i=0;i<nn;i++)

    {

        cout<<"\n"<<ch[i]<<" Table";

        cout<<"\nNode\tDist\tVia";

        for(j=0;j<nn;j++)

        {

            cout<<"\n"<<ch[j]<<"\t"<<final[i][j]<<"\t";

            if(i==via[i][j])

                cout<<"-";

            else

                cout<<ch[via[i][j]];

        }

    }

 

    getch();

}




----------------------------------------Socket Programming------------------------------------------


Client side.....



#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<string.h>

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>

#include<netdb.h>


void error(const  char* msg)

{

    perror(msg);

    exit(1);

}

int main(int argc, char *argv[])

{

    int sockfd, port_no, temp;

    struct sockaddr_in server_address;

    struct hostent *server;

    char buffer[255];

    printf("Enter 'BHOKME' to disconnnect from Server \n");


    if(argc<3)

    {

        printf("Either Port number or host address not entered");

        exit(1);

    }


    port_no = atoi(argv[2]);

    sockfd = socket(AF_INET, SOCK_STREAM, 0  );

    

    if(sockfd < 0)

    {

        error("Error opening the socket");

    }


server = gethostbyname(argv[1]);

if(server == NULL)

{

    printf("No Host exist with such address");

}


bzero((char *) &server_address,  sizeof(server_address));

server_address.sin_family = AF_INET;

bcopy((char *) server->h_addr, (char *) &server_address.sin_addr, server->h_length);

server_address.sin_port = htons(port_no);


if(connect(sockfd, (struct sockaddr*) &server_address, sizeof(server_address)) < 0)

   {

    error("Connection Failed");

   }



while(1)

{

    bzero(buffer, 255);

    fgets(buffer, 255, stdin);

    temp = write(sockfd, buffer, strlen(buffer));

    if(temp < 0)

    {

error("Error wile writing");

    }

    bzero(buffer, 255);

    temp = read(sockfd, buffer, 255);

    if(temp < 0)

    {

error("Error while reading");

    }

printf("Server :  %s",buffer);


int trigger = strncmp("BHOKME", buffer, 6);

if(trigger == 0)

{   

break;  

}

}


close(sockfd);

return 0;


}








server Side....


#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<string.h>

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>


void error(const  char* msg)

{

    perror(msg);

    exit(1);

}

int main(int argc, char *argv[])

{

printf("Enter 'BHOKME' to Close Server \n");

    if(argc<2)

    {

        printf("Port Number not Entered \n");

        exit(1);

    }


    int sockfd, sockfd_new, port_no, temp;

    char buffer[255];


    struct sockaddr_in server_address, client_address;

    socklen_t client_len;


    sockfd = socket(AF_INET, SOCK_STREAM, 0);

    if(sockfd<0)

    {

        error("Error Openinng Socket");

    }

    bzero((char *) &server_address, sizeof(server_address));

    port_no = atoi(argv[1]);

    

    server_address.sin_family = AF_INET;

    server_address.sin_addr.s_addr = INADDR_ANY;

    server_address.sin_port = htons(port_no);



    if(bind(sockfd, (struct sockaddr *) &server_address, sizeof(server_address))   < 0 )

    {

            error("Binding Failed");

    }


    listen(sockfd, 5);

    client_len = sizeof(client_address);


    sockfd_new = accept(sockfd, (struct sockaddr*) &client_address, &client_len);


    if(sockfd_new < 0)

    {

        error("Error while accepting the input");

    }


    while(1)

    {

        bzero(buffer, 255);

        temp = read(sockfd_new, buffer, 255);

        if(temp < 0)

        {

            error("Error While reading");

        }

        printf("client : %s \n", buffer );

        bzero(buffer, 255);

        fgets(buffer, 255, stdin);


        temp = write(sockfd_new, buffer, strlen(buffer));

        if(temp < 0)

        {

            error("Error while writing");

        }


        int trigger = strncmp("BHOKME", buffer, 6);

        if(trigger == 0)

        {   break;  }

    }

    close(sockfd_new);

    close(sockfd);

    return 0;




}










------------------------------

server side...


#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#define PORT 8080
int main(int argc, char const* argv[])
{
int server_fd, new_socket, valread;
struct sockaddr_in address;
int opt = 1;
int addrlen = sizeof(address);
char buffer[1024] = { 0 };
char* msg = "Hello from server";
// Creating socket file descriptor
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket failed");
exit(EXIT_FAILURE);
}
// Forcefully attaching socket to the port 8080
if (setsockopt(server_fd, SOL_SOCKET,
SO_REUSEADDR | SO_REUSEPORT, &opt,
sizeof(opt))) {
perror("setsockopt");
exit(EXIT_FAILURE);
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(PORT);
// Forcefully attaching socket to the port 8080
if (bind(server_fd, (struct sockaddr*)&address,
sizeof(address))
< 0) {
perror("bind failed");
exit(EXIT_FAILURE);
}
if (listen(server_fd, 3) < 0) {
perror("listen");
exit(EXIT_FAILURE);
}
if ((new_socket
= accept(server_fd, (struct sockaddr*)&address,
(socklen_t*)&addrlen))
< 0) {
perror("accept");
exit(EXIT_FAILURE);
}
valread = read(new_socket, buffer, 1024);
printf("%s\n", buffer);
send(new_socket, msg, strlen(msg), 0);
printf("Hello message sent\n");
// buffer = { 0 };
valread = read(new_socket, buffer, 1024);
printf("Enter new msg: ");
scanf("%s",msg);
printf("%s\n", buffer);
send(new_socket, msg, strlen(msg), 0);
printf("New message sent\n");
// closing the connected socket
close(new_socket);
// closing the listening socket
shutdown(server_fd, SHUT_RDWR);
return 0;
}





----------------------------


Client side

#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#define PORT 8080
int main(int argc, char const* argv[])
{
int sock = 0, valread, client_fd;
struct sockaddr_in serv_addr;
char* msg = "Hello from client";
char buffer[1024] = { 0 };
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("\n Socket creation error \n");
return -1;
}
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
// Convert IPv4 and IPv6 addresses from text to binary
// form
if (inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)
<= 0) {
printf(
"\nInvalid address/ Address not supported \n");
return -1;
}
if ((client_fd
= connect(sock, (struct sockaddr*)&serv_addr,
sizeof(serv_addr)))
< 0) {
printf("\nConnection Failed \n");
return -1;
}
send(sock, msg, strlen(msg), 0);
printf("Hello message sent\n");
valread = read(sock, buffer, 1024);
printf("%s\n", buffer);
// closing the connected socket
close(client_fd);
return 0;
}






Saturday, 10 September 2022

    Overview of Distributed Data Warehouse 

 

Introduction

Most companies develop and maintain a single, centralised data warehouse system. Only corporate headquarters uses an integrated view of the data in the warehouse, which is integrated across the entire organisation. The corporation employs a centralised business model. Given the amount of data in the data warehouse, a single, central store of data makes sense. Even if data could be integrated, if it were dispersed among multiple local sites, it would be challenging to access. Politics, economics, and technology are, in essence, strongly in favour of a single, central data warehouse.

 

Distributed Warehouse

When creating a data warehouse, there are two options: distributed data warehouses and basic data warehouses. As a result, several companies made the decision to create flexible, small data marts that are tailored to particular business sectors. Distributed data warehousing is a type of data warehousing architecture where data is stored and managed across a network of decentralized, independent computer systems. This architecture is often used in organizations with large, distributed databases. The distributed data warehousing system is more and more popular and useful with the latest technology. All the business corporations, institutes or any management deals with a large amount of data so it is not feasible for them to manage it for that purpose they need to distribute that data for further processes. The data is stored at different data warehouse sites locally should operate simultaneously to create one large data processing unit.

 

Framework For Distributed Data Warehouses:

Inmon's Approach

Inmon's method assumes that data stored in the global and local data warehouses are mutually exclusive. Data from a local data warehouse is pre-staged at each local site before being sent to the central global data warehouse, which offers the global DSS (Decision Support System) functionality.

Fig-1: Inmon’s Approach to Distributed Data Warehouses


Inmon's Approach to Distributed Data Warehouses


White's Approach

White's method, commonly referred to as a "Two-Tier Data Warehouse," combines a decentralised data mart with a centralised data warehouse. A particular user or user group will find value in the denormalized and summarised data found in the data mart or decentralised data mart. White's core data warehouse houses cleansed and normalised detailed data that is periodically pulled from operational systems. Data collections made up of data obtained from the detailed base data are kept up to date in the central data warehouse. Data collections, which can include both summarised and denormalized comprehensive data, provide the user's perspective of warehouse data.

Fig-2: White's Approach to Distributed Data Warehouses.


White's Approach to Distributed Data Warehouses.




  • The Distributed Warehouse Architecture

The Distributed System Architecture The ANSI/SPARC design, which comprises three levels of schemas—internal, conceptual, and external—is the foundation of the distributed data warehouse system architecture. The data integration layer, which contains the source database systems and the processes necessary to integrate the item, is the first layer of the four-tiered architecture [1]. Using a homogenous model, the data staging layer merges subject-oriented and recent detailed data. restricted ability to adapt to changing information needs. As adjustments are made to the operational systems, the data distribution layer allocates, segments, and 3 updates the distributed data warehouse. By giving a corporate-wide view of the dispersed data throughout the network, the distributed data warehouse management lager is in charge of interacting with the decision support environment.

  • Data Integration Layer

The data integration layer consists of the source databases available across the sites and the integration and transformation tools. Each source at each site has its own Local Internal Schema (LIS) and Local Conceptual Schema. The LIS defines the physical data organization on the source database.

  • The Data Staging Layer

The data staging layer stores the integrated, subject oriented, current-value and detailed data. The underlying model for the staging layer is a canonical data model. The staging layer will be transformed into the Global Conceptual Schema (GCS) under the data warehouse model.

  • The Data Distribution Layer

The data distribution layer provides the following processes: fragmentation, allocation and updating the distributed data warehouse. The main objective of the fragmentation and allocation processes is to minimize the total transaction processing cost for a given set of transactions.

  • Manager Layer

Distributed data warehouse manager layer manages the fragments at each site. Fragments represent the integrated, subject oriented, non-Volatile, time Variant and detailed data. End users at each local site are supported by External Schema (ES) to allow them to execute the DSS applications.


Types of Distributed Data Warehouse [DDW]–

There are 3 types of Distributed data warehouse re as follows:

1.     Local and Global Data Warehouses-

A Local data which is unique to the local operating system and global is integrated data.

For example, Fig1-SBI is a local DW and RBI is a Global DW.

2.     Technologically distributed data warehouse-

A DW which is logically a single DW but physically it is a combination of multiple data warehouses.

3.     Independently evolving distributed data warehouse-

It is made in an uncoordinated data warehouse. If the storage of first data warehouse is full then there will be a second DW and after that one by one it’s going on.

 

Tuesday, 10 August 2021

Waqar Farooqui waqa26r.blogspot.com/

Hello Everyone

QUESTION

 block of mass 10 kg is pulled by a force of 10 N in the direction making an angle of 60 degree with horizontal. The acceleration of the block in m/s2 is??


ANS:  The correct  answer is     [ 0.5   ]




QUESTION    NO . 2


The man has a mass of 80 kg and sits at r from the centre of the rotating platform. The maximum velocity at which he can slip from the rotating platform is 2.97 m/s and the coefficient of static friction between contact surfaces is 0.3. Determine the distance r.


ANS : The  correct  answer  is   [  3.0 m ]



This is  Btech students  for jee students for mht cet students 

MCQ type question and answer 

Accessing and Parsing OneNote Notebook Content from Azure Storage Containers

Accessing and Parsing OneNote Notebook Content from Azure Storage Containers OneNote is a powerful tool for digital note-taking and collabor...