Technocrat

  • Home
Showing posts with label Networking. Show all posts
Showing posts with label Networking. Show all posts

Sunday, May 3, 2015

Addition of two numbers on Server sent from Client [TCP] using C

 Sumit Kar     May 03, 2015     C - Programming, Networking, Socket Program     No comments   


/* tcpClient.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <string.h>

#include <strings.h>





#define MAX_MSG 100

#define SERVER_ADDR "127.0.0.1"

#define CLIENT_ADDR "127.0.0.1"

#define SERVER_PORT 3786

#define CLIENT_PORT 8229



 main () {



  int sd, rc, i,n;

  struct sockaddr_in clientAddr, servAddr;

  char line[MAX_MSG];





  /**********************************/

  /* build server address structure */

  /**********************************/



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

  servAddr.sin_family = AF_INET;

  servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);

  servAddr.sin_port = htons(SERVER_PORT);



/*

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

  servAddr.sin_family = AF_INET;

  inet_aton(SERVER_ADDR, &servAddr.sin_addr);

  servAddr.sin_port = htons(SERVER_PORT);

*/



  /**********************************/

  /* build client address structure */

  /**********************************/



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

  clientAddr.sin_family = AF_INET;

  clientAddr.sin_addr.s_addr = INADDR_ANY;

  clientAddr.sin_port = htons(0);



/*

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

  clientAddr.sin_family = AF_INET;

  clientAddr.sin_addr.s_addr = inet_addr(CLIENT_ADDR);

  clientAddr.sin_port = htons(CLIENT_PORT);

*/



  /************************/

  /* create stream socket */

  /************************/



  sd = socket(AF_INET, SOCK_STREAM, 0);

  printf("successfully created stream socket \n");



  /**************************/

  /* bind local port number */

  /**************************/



  bind(sd, (struct sockaddr *) &clientAddr, sizeof(clientAddr));

  printf("bound local port successfully\n");



  /*********************/

  /* connect to server */

  /*********************/



  connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));

  printf("connected to server successfully\n");



    /***********************/

    /* send data to server */

    /***********************/



  do{

    printf("Enter 1st number : ");

    scanf("%s", line);



    send(sd, line, strlen(line) + 1, 0);

    printf("data sent (%s)\n", line);  

    printf("Enter 2nd number : ");

    scanf("%s", line);

    send(sd, line, strlen(line) + 1, 0);

    printf("data sent (%s)\n", line);

 

    n=recv(sd, line, MAX_MSG, 0);

    printf("received from server %s\n", line);

  }while(strcmp(line, "quit"));





  printf("closing connection with the server\n");

  close(sd);

}












Addition of two numbers on Server sent from Client [TCP] using C



/* tcpServer.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <strings.h>

#include <string.h>







#define MAX_MSG 100

#define SERVER_ADDR "127.0.0.1"

#define SERVER_PORT 3786





 main ( ) {



  int sd, newSd, cliLen, n,num1,num2,sum;



  struct sockaddr_in cliAddr, servAddr;

  char line[MAX_MSG],line1[MAX_MSG],line2[MAX_MSG];





  /**********************************/

  /* build server address structure */

  /**********************************/



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

  servAddr.sin_family = AF_INET;

  servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);

  servAddr.sin_port = htons(SERVER_PORT);



/*

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

  servAddr.sin_family = AF_INET;

  inet_aton(SERVER_ADDR, &servAddr.sin_addr);

  servAddr.sin_port = htons(SERVER_PORT);

*/





  /************************/

  /* create stream socket */

  /************************/



  sd = socket(AF_INET, SOCK_STREAM, 0);

  printf("successfully created stream socket \n");



  /**************************/

  /* bind local port number */

  /**************************/



  bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));

  printf("bound local port successfully\n");





  /********************************/

  /* specify number of concurrent */

  /* clients to listen for        */

  /********************************/



  listen(sd,5);





  while(1) {



    printf("waiting for client connection on port TCP %u\n",SERVER_PORT);



    /*****************************/

    /* wait for client connection*/

    /*****************************/  



    cliLen = sizeof(cliAddr);

    newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen);



    printf("received connection from host [IP %s ,TCP port %d]\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port));



    /*****************************/

    /* wait for data from client */

    /*****************************/    

 

    do{

      memset(line,0x0,MAX_MSG);

 

      n=recv(newSd, line, MAX_MSG, 0);

      num1=atoi(line);

   

      n=recv(newSd, line, MAX_MSG, 0);

      num2=atoi(line);



   

      sum=num1+num2;



      sprintf(line1,"%d",sum);

   

 

      printf("received from host [IP %s ,TCP port %d] : %s\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port), line1);

send(newSd, line1, strlen(line1) + 1, 0);



    }while(abs(strcmp(line, "quit")));





    /**************************/

    /* close client connection*/

    /**************************/  



    printf("closing connection with host [IP %s ,TCP port %d]\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port));



    close(newSd);

  }

}




Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Concatenation of two strings sent from Client on the Server - [ TCP ] using C

 Sumit Kar     May 03, 2015     C - Programming, Networking, Socket Program     No comments   


/* tcpClient.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <string.h>

#include <strings.h>





#define MAX_MSG 100

#define SERVER_ADDR "127.0.0.1"

#define CLIENT_ADDR "127.0.0.1"

#define SERVER_PORT 3786

#define CLIENT_PORT 8229



 main () {



  int sd, rc, i,n;

  struct sockaddr_in clientAddr, servAddr;

  char line[MAX_MSG];





  /**********************************/

  /* build server address structure */

  /**********************************/



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

  servAddr.sin_family = AF_INET;

  servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);

  servAddr.sin_port = htons(SERVER_PORT);



/*

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

  servAddr.sin_family = AF_INET;

  inet_aton(SERVER_ADDR, &servAddr.sin_addr);

  servAddr.sin_port = htons(SERVER_PORT);

*/



  /**********************************/

  /* build client address structure */

  /**********************************/



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

  clientAddr.sin_family = AF_INET;

  clientAddr.sin_addr.s_addr = INADDR_ANY;

  clientAddr.sin_port = htons(0);



/*

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

  clientAddr.sin_family = AF_INET;

  clientAddr.sin_addr.s_addr = inet_addr(CLIENT_ADDR);

  clientAddr.sin_port = htons(CLIENT_PORT);

*/



  /************************/

  /* create stream socket */

  /************************/



  sd = socket(AF_INET, SOCK_STREAM, 0);

  printf("successfully created stream socket \n");



  /**************************/

  /* bind local port number */

  /**************************/



  bind(sd, (struct sockaddr *) &clientAddr, sizeof(clientAddr));

  printf("bound local port successfully\n");



  /*********************/

  /* connect to server */

  /*********************/



  connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));

  printf("connected to server successfully\n");



    /***********************/

    /* send data to server */

    /***********************/



  do{

    printf("Enter string to send to server : ");

    scanf("%s", line);



    send(sd, line, strlen(line) + 1, 0);

    printf("data sent (%s)\n", line);  

    printf("Enter another string to send to server : ");

    scanf("%s", line);

    send(sd, line, strlen(line) + 1, 0);

    printf("data sent (%s)\n", line);

     n=recv(sd, line, MAX_MSG, 0);

   

      printf("received from server %s\n", line);

  }while(strcmp(line, "quit"));





  printf("closing connection with the server\n");

  close(sd);

}












Concatenation of two strings sent from Client on the Server - [ TCP ] using C



/* tcpServer.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <strings.h>

#include <string.h>







#define MAX_MSG 100

#define SERVER_ADDR "127.0.0.1"

#define SERVER_PORT 3786





 main ( ) {



  int sd, newSd, cliLen, n;



  struct sockaddr_in cliAddr, servAddr;

  char line[MAX_MSG],line1[MAX_MSG];





  /**********************************/

  /* build server address structure */

  /**********************************/



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

  servAddr.sin_family = AF_INET;

  servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);

  servAddr.sin_port = htons(SERVER_PORT);



/*

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

  servAddr.sin_family = AF_INET;

  inet_aton(SERVER_ADDR, &servAddr.sin_addr);

  servAddr.sin_port = htons(SERVER_PORT);

*/





  /************************/

  /* create stream socket */

  /************************/



  sd = socket(AF_INET, SOCK_STREAM, 0);

  printf("successfully created stream socket \n");



  /**************************/

  /* bind local port number */

  /**************************/



  bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));

  printf("bound local port successfully\n");





  /********************************/

  /* specify number of concurrent */

  /* clients to listen for        */

  /********************************/



  listen(sd,5);





  while(1) {



    printf("waiting for client connection on port TCP %u\n",SERVER_PORT);



    /*****************************/

    /* wait for client connection*/

    /*****************************/  



    cliLen = sizeof(cliAddr);

    newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen);



    printf("received connection from host [IP %s ,TCP port %d]\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port));



    /*****************************/

    /* wait for data from client */

    /*****************************/    

 

    do{

      memset(line,0x0,MAX_MSG);

 

      n=recv(newSd, line, MAX_MSG, 0);

     strcpy(line1,line);

      n=recv(newSd, line, MAX_MSG, 0);

strcat(line1,line);



 

      printf("received from host [IP %s ,TCP port %d] : %s\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port), line1);

send(newSd, line1, strlen(line1) + 1, 0);



    }while(abs(strcmp(line, "quit")));





    /**************************/

    /* close client connection*/

    /**************************/  



    printf("closing connection with host [IP %s ,TCP port %d]\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port));



    close(newSd);

  }

}




Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

UDP Client-Server Program (Command Line) using C

 Sumit Kar     May 03, 2015     C - Programming, Networking, Socket Program     No comments   


/* udpClient.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include<stdlib.h>

#include <unistd.h>

#include <string.h>

#include <strings.h>

#include <sys/time.h>





#define MAX_MSG 100







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



  int i, sd, rc, tempLen, n, portno;

  struct sockaddr_in remoteServAddr, tempAddr;

  struct sockaddr_in cliAddr;

  char server[20];

  char msg[MAX_MSG];

  if(argc<3)

    {

         fprintf(stderr,"Usage : %s hostname port\n Press Ctrl+C",argv[0]);

     

    }

  portno=atoi(argv[2]);

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

     server[i]=argv[1][i];

    if(server==NULL)

    {

          printf("Error, no such host");    

    }





  /**********************************/

  /* build server address structure */

  /**********************************/



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

  remoteServAddr.sin_family = AF_INET;

  remoteServAddr.sin_addr.s_addr = inet_addr(server);

  remoteServAddr.sin_port = htons(portno);





  /**************************/

  /* create datagram socket */

  /**************************/



  sd = socket(AF_INET,SOCK_DGRAM,0);

  if(sd<0)

          printf("Error opening socket");

  else

          printf("successfully created datagram socket\n");





  do {



    /***********************/

    /* send data to server */

    /***********************/



    printf("Enter data to send : ");

    scanf("%s", msg);



    sendto(sd, msg, strlen(msg)+1, 0, (struct sockaddr *) &remoteServAddr,

sizeof(remoteServAddr));



 

  }while(strcmp(msg, "quit"));



 close(sd);

}









/* udpServer.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <string.h>





#define MAX_MSG 100







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

  char server[20];

  int i,sd, rc, n, cliLen,portno;

  struct sockaddr_in cliAddr, servAddr;

  char msg[MAX_MSG];



  if(argc<3)

    {

         fprintf(stderr,"Usage : %s hostname port\n Press Ctrl+C",argv[0]);

     

    }

  portno=atoi(argv[2]);

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

     server[i]=argv[1][i];

    if(server==NULL)

    {

          printf("Error, no such host");    

    }



  /**********************************/

  /* build server address structure */

  /**********************************/



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

  servAddr.sin_family = AF_INET;

  servAddr.sin_addr.s_addr = inet_addr(server);

  servAddr.sin_port = htons(portno);



  /**************************/

  /* create datagram socket */

  /**************************/





  sd=socket(AF_INET, SOCK_DGRAM, 0);

  printf("datagram socket created succefully\n");

  /**************************/

  /* bind local port number */

  /**************************/



  bind (sd, (struct sockaddr *) &servAddr,sizeof(servAddr));

  printf("successfully bound local address\n");



  printf("waiting for data on port UDP %u\n", portno);







  while(1) {

 

    /* init buffer */



    memset(msg,0x0,MAX_MSG);



    /****************************/

    /* receive data from client */

    /****************************/





    cliLen = sizeof(cliAddr);

    n = recvfrom(sd, msg, MAX_MSG, 0, (struct sockaddr *) &cliAddr, &cliLen);



    printf("from %s: UDP port %u : %s \n",

   inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port),msg);







  }



return 0;



}







Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

UDP Client-Server Program using C

 Sumit Kar     May 03, 2015     C - Programming, Networking, Socket Program     No comments   



UDP Client-Server Program using C



/* udpClient.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <string.h>

#include <sys/time.h>





#define MAX_MSG 100

#define SERVER_ADDR "127.0.0.1"

#define SERVER_PORT 9227





 main( ) {



  int sd, rc, tempLen, n;

  struct sockaddr_in cliAddr, remoteServAddr, tempAddr;

  char msg[MAX_MSG];







  /**********************************/

  /* build server address structure */

  /**********************************/



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

  remoteServAddr.sin_family = AF_INET;

  remoteServAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);

  remoteServAddr.sin_port = htons(SERVER_PORT);





  /**************************/

  /* create datagram socket */

  /**************************/



  sd = socket(AF_INET,SOCK_DGRAM,0);

  printf("successfully created datagram socket\n");





  do {



    /***********************/

    /* send data to server */

    /***********************/



    printf("Enter data to send : ");

    scanf("%s", msg);



    sendto(sd, msg, strlen(msg)+1, 0, (struct sockaddr *) &remoteServAddr,

sizeof(remoteServAddr));



 

  }while(strcmp(msg, "quit"));



 close(sd);

}












/* udpServer.c */





#include <sys/types.h>


#include <sys/socket.h>


#include <netinet/in.h>


#include <arpa/inet.h>


#include <netdb.h>


#include <stdio.h>


#include <unistd.h> 


#include <string.h> 








#define MAX_MSG 100


#define SERVER_ADDR "127.0.0.1"


#define SERVER_PORT 9227








 main( ) {


  


  int sd, rc, n, cliLen;


  struct sockaddr_in cliAddr, servAddr;


  char msg[MAX_MSG];








  /**********************************/


  /* build server address structure */


  /**********************************/  





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


  servAddr.sin_family = AF_INET;


  servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);


  servAddr.sin_port = htons(SERVER_PORT);





  /**************************/


  /* create datagram socket */


  /**************************/





  sd=socket(AF_INET, SOCK_DGRAM, 0);


  printf("datagram socket created succefully\n");





  /**************************/


  /* bind local port number */


  /**************************/





  bind (sd, (struct sockaddr *) &servAddr,sizeof(servAddr));


  printf("successfully bound local address\n");





  printf("waiting for data on port UDP %u\n", SERVER_PORT);











  while(1) {


    


    /* init buffer */





    memset(msg,0x0,MAX_MSG);





    /****************************/


    /* receive data from client */


    /****************************/  








    cliLen = sizeof(cliAddr);


    n = recvfrom(sd, msg, MAX_MSG, 0, (struct sockaddr *) &cliAddr, &cliLen);





    printf("from %s: UDP port %u : %s \n", 


  inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port),msg);




  }





return 0;





}






Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Friday, April 17, 2015

TCP Echo Server - Echo Client Program using C

 Sumit Kar     April 17, 2015     C - Programming, Networking, Socket Program     No comments   


/* tcpechoServer.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <strings.h>

#include <string.h>



#define MAX_MSG 100

#define SERVER_ADDR "127.0.0.1"

#define SERVER_PORT 3786





 main ( ) {



  int sd, newSd, cliLen, n;



  struct sockaddr_in cliAddr, servAddr;

  char line[MAX_MSG], line_r[MAX_MSG];





  /**********************************/

  /* build server address structure */

  /**********************************/



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

  servAddr.sin_family = AF_INET;

  servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);

  servAddr.sin_port = htons(SERVER_PORT);



/*

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

  servAddr.sin_family = AF_INET;

  inet_aton(SERVER_ADDR, &servAddr.sin_addr);

  servAddr.sin_port = htons(SERVER_PORT);

*/





  /************************/

  /* create stream socket */

  /************************/



  sd = socket(AF_INET, SOCK_STREAM, 0);

  printf("successfully created stream socket \n");



  /**************************/

  /* bind local port number */

  /**************************/



  bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));

  printf("bound local port successfully\n");





  /********************************/

  /* specify number of concurrent */

  /* clients to listen for        */

  /********************************/



  listen(sd,5);





  while(1) {



    printf("waiting for client connection on port TCP %u\n",SERVER_PORT);



    /*****************************/

    /* wait for client connection*/

    /*****************************/  



    cliLen = sizeof(cliAddr);

    newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen);



    printf("received connection from host [IP %s ,TCP port %d]\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port));



    /*****************************/

    /* wait for data from client */

    /*****************************/    

 

    do{

      memset(line,0x0,MAX_MSG);

 

      n=recv(newSd, line, MAX_MSG, 0);

      line[n]='\n';

   

      printf("received from host [IP %s ,TCP port %d] : %s\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port), line);

   

      strcpy(line_r,line);

      send(newSd, line_r, strlen(line_r) + 1, 0);

      printf("data echoed (%s)\n", line_r);



    }while(abs(strcmp(line, "quit")));





    /**************************/

    /* close client connection*/

    /**************************/  



    printf("closing connection with host [IP %s ,TCP port %d]\n",

                 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port));



    close(newSd);

  }

}





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





/* tcpechoClient.c */



#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <stdio.h>

#include <unistd.h>

#include <string.h>

#include <strings.h>





#define MAX_MSG 100

#define SERVER_ADDR "127.0.0.1"

#define CLIENT_ADDR "127.0.0.1"

#define SERVER_PORT 3786

#define CLIENT_PORT 8229



 main () {



  int sd, rc, i, n;

  struct sockaddr_in clientAddr, servAddr;

  char line[MAX_MSG],line_r[MAX_MSG];





  /**********************************/

  /* build server address structure */

  /**********************************/



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

  servAddr.sin_family = AF_INET;

  servAddr.sin_addr.s_addr = inet_addr(SERVER_ADDR);

  servAddr.sin_port = htons(SERVER_PORT);



/*

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

  servAddr.sin_family = AF_INET;

  inet_aton(SERVER_ADDR, &servAddr.sin_addr);

  servAddr.sin_port = htons(SERVER_PORT);

*/



  /**********************************/

  /* build client address structure */

  /**********************************/



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

  clientAddr.sin_family = AF_INET;

  clientAddr.sin_addr.s_addr = INADDR_ANY;

  clientAddr.sin_port = htons(0);



/*

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

  clientAddr.sin_family = AF_INET;

  clientAddr.sin_addr.s_addr = inet_addr(CLIENT_ADDR);

  clientAddr.sin_port = htons(CLIENT_PORT);

*/



  /************************/

  /* create stream socket */

  /************************/



  sd = socket(AF_INET, SOCK_STREAM, 0);

  printf("successfully created stream socket \n");



  /**************************/

  /* bind local port number */

  /**************************/



  bind(sd, (struct sockaddr *) &clientAddr, sizeof(clientAddr));

  printf("bound local port successfully\n");



  /*********************/

  /* connect to server */

  /*********************/



  connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));

  printf("connected to server successfully\n");



    /***********************/

    /* send data to server */

    /***********************/



  do{

    printf("Enter string to send to server : ");

    scanf("%s", line);



    send(sd, line, strlen(line) + 1, 0);

    printf("data sent (%s)\n", line);

    n=recv(sd, line_r, MAX_MSG, 0);

      line_r[n]='\n';

 

      printf("received from server [IP %s ,TCP port %d] : %s\n",

                 inet_ntoa(servAddr.sin_addr), ntohs(servAddr.sin_port), line_r);

  }while(strcmp(line, "quit"));





  printf("closing connection with the server\n");

  close(sd);

}



Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Tuesday, April 7, 2015

Net Neutrality

 Sumit Kar     April 07, 2015     Facebook, Google, Internet, Networking, Technology, WhatsApp, Yahoo     No comments   



Net Neutrality


What is net neutrality?



If net neutrality was to be defined in a single line it would go like this:


“The premise of net neutrality is that all data on the Internet should be treated equally.”

Expanding on the above, a more comprehensive definition would be:



“Net neutrality means that Internet service providers (like Airtel, Reliance etc. who are responsible for our broadband and mobile Internet connections) shouldn’t be allowed to give preferential treatment to select websites, online services or apps. These ISPs should also not be allowed to discriminate against any websites, online services or apps.”





Net neutrality means Internet that allows everyone to communicate freely. It means a service provider should allow access to all content and applications regardless of the source and no websites or pages should be blocked, as long as they aren’t illegal. All websites can co-exist without hampering others. All websites are accessible at the same speed and no particular website of application is favored. For instance – like electricity, common for all. Net neutrality also means all web sites and content creators are treated equal, and you no one have to pay extra for faster Internet speed to a particular site/service.



This means that ISPs can’t ask some websites, online services or apps to pay extra in order to make it easier for consumers to access them. For instance, Airtel shouldn’t be allowed to take money from Flipkart and then let Airtel broadband and mobile Internet customers load the Flipkart website faster, or scrap all data charges when the Flipkart app is being used.



Conversely, an ISP shouldn’t be allowed to penalize websites, online services or apps because they haven’t paid extra charges. Continuing the same example from above, Airtel shouldn’t be allowed to put competing e-commerce websites like Snapdeal or Amazon at a disadvantage by giving Flipkart a boost just because Flipkart paid up. Also, while currently this discrimination may only come to life in the form of advantages given to companies that pay the ISP, it’s not very difficult to imagine a time when certain websites and apps are made unusable or entirely blocked on certain networks just because they didn’t pay up.


Why should you bother or what will happen if there is no net neutrality?



Net Neutrality




To put it out straight, if there is no net neutrality, the Internet won’t function as we’ve known it too. It will mean Internet Service Providers (ISP) will be able to charge companies like YouTube or Netflix as they consume more bandwidth, and eventually the load of the extra sum will be pushed to the consumers. Similarly, ISPs can then create slow as well as fast Internet lanes, which will mean all websites cannot be accessed at the same speed and one can do so only on paying an additional sum. For instance, currently, I have a standard data package and access all the content at the same speed, irrespective of whether its an international website or Indian. Similarly, ISPs can also charge extra for the free calls you make using services like WhatsApp, Skype and others, and eventually the load of additional payable sum by the OTT players will be pushed onto consumers.



Net Neutrality is extremely important for small business owners, startups and entrepreneurs, who can simply launch their businesses online, advertise the products and sell them openly, without any discrimination. It is essential for innovation and creating job opportunities. Big companies like Google, Twitter and several others are born out of net neutrality. With increasing Internet penetration in India and given that we are becoming a breeding ground for startups and entrepreneurs, the lack of net neutrality should worry us greatly. Besides, it is very important for freedom of speech, so that one can voice their opinion without the fear of being blocked or banned.




Even though everybody and their grandmother supports net neutrality, is there a contrarian viewpoint?


As it always happens in a debate, net neutrality is being both derided and defended by different parties. And even though it may appear like net neutrality has received universal support, it is important to understand the other side of the debate as well.

But first, let’s take a quick look at why net neutrality is being defended:

1. Without net neutrality, it would be very easy for ISPs to mould the browsing habits of its users with the help of pricing slabs, different speeds for different sites and other methods. So, if Airtel wanted its users to visit Flipkart, it would make it exceedingly easy and advantageous to do so and put competing sites on the back foot which would clearly be an anti-competition move.

2. Net neutrality also ensures that small, new companies can compete against established big names on the Internet fairly. If net neutrality did not exist then big companies would shackle their competition with the implicit ability to be able pay more to the ISPs to ensure better service, something that most start-ups wouldn’t be able to do.

3. Now, this scenario may lie at the furthest end of the slippery slope, but here it is: since the absence of net neutrality could mean that an ISP will get money from companies, that relationship may be enough to compel the ISP to mute online criticism against one of its paying partners.

4. Another scenario that exists without net neutrality is that the Internet becomes a stratified mess and you’ll be forced to choose packages of websites and services like you do with your DTH subscription. If you want unrestricted access to the Internet, the ISPs could force you to pay through the nose.


Net Neutrality, Internet



5. The anti-net neutrality arguments become even more vociferous when it comes to VoIP and messaging apps like WhatsApp and Viber. Since these services directly affect the telcos’ bottomline, there is the significant possibility that the companies behind these apps will have to register for licenses in order to conduct operations in India. This means that unless the companies behind messaging and VoIP apps decide to pay the government for licenses, you won’t be able to use them.


Net Neutrality, Airtel, Reliance, Tata, internet, free





These are only a few of the many arguments that net neutrality proponents put forward in defence of keeping the Internet neutral. However, when we get to the debate against net neutrality, the focus of the arguments is markedly different. While the pro net neutrality talking points almost always have the consumer as their focal point, the other side of the debate seems to be focused on the telecom operators and how a ‘neutral’ Internet ensures financial doom. In fact, TRAI recently published a consultation paper that almost exclusively focuses on how many VoIP services, apps and websites are taking undue advantage of the infrastructure set up by telcos who spent bucketloads of money setting it all up. It’s a long paper but even if you just skim through it, this theme jumps out at you.




A graph from the TRAI policy paper that shows drop in SMS use.
A graph from the TRAI policy paper that shows drop in SMS use. 



The fact is that in order to support dismantling net neutrality, you have to believe in the telcos’ claim that without earning revenue from VoIP services and websites like YouTube, they will be forced to either pass on huge costs to the consumer or to accept massive losses.




A graph from the TRAI policy paper showing dropping growth of voice calls over mobile & increasing growth of VoIP.
A graph from the TRAI policy paper showing dropping growth of voice calls over mobile & increasing growth of VoIP. 



Apart from the arguments that are in line with the above, let’s take a look at some of the other talking points put forward against net neutrality:

1. ISPs argue that they can increase the overall efficiency of their networks if they’re allowed to ‘actively’ manage them. This means that ISPs can decide how to shape Internet traffic so that heavy Internet users don’t affect the experience of light users. ISPs also claim that this will allow them to give preference to certain types of online services that are necessary and should be prioritized, such as communication channels used by hospitals or emergency response services during a disaster.

2. ISPs also argue that adopting a blanket net neutrality policy will give rise to security risks and increase piracy and cyber crime. ISPs claim that the only way they can help the government to police the Internet better is if they can manage it.

3. One of the more ideological arguments against net neutrality is that it will give too much power to the government organisation that will be responsible for enforcing net neutrality. Some net neutrality detractors have argued that it’s better for user privacy and competition if the ISPs themselves manage the Internet rather than letting a governmental body have control.

It may be simplistic to say so but it does appear that the anti-net neutrality stance basically boils down to one point: You should implicitly trust the ISPs because they will always have your best interests at heart. Now, whether you agree with that statement should tell you where you stand on the net neutrality debate.

There is, however, one aspect of the telcos services, which goes against net neutrality, that appears worth considering, especially in a country like India. I am specifically talking about a service like Internet.org which could work as a great tool to increase Internet penetration in rural areas and places where Internet use is often looked at as a luxury. Under the Internet.org service, Reliance mobile users will be able to access 38 websites for free, including popular ones like Facebook, Facebook Messenger, Wikipedia, NDTV, Aaj Tak, BBC, Cricinfo, Bing and OLX. Yes, it does seem like that list was drawn arbitrarily but it can’t be denied that these are very popular websites. I cannot in good conscience say that someone who couldn’t afford to use the Internet shouldn’t get to do so in whatever capacity. Do I wish services like Internet.org offered more choice or even let users pick the websites that they’d want to access for free? Yes, that would be ideal but I’m also aware of the economic realities. If the scope of services like Internet.org is focused towards increasing rural Internet penetration and awareness, then I can’t really argue against it, not when I have easy access to the Internet at relatively decent speeds while many others don’t.

The debate over whether services like Internet.org flagrantly violate net neutrality and their efficacy in helping bridge the digital divide in Internet starved areas of the country has been wonderfully talked about over at Medianama.  


How activists have been fighting for it in the west?


Net neutrality isn’t something new and many activists have been battling to achieve it in the west.



In 2010, FCC had passed an order to prevent broadband Internet service providers from blocking or meddling with the traffic on the Web. Known as the ‘Open Internet Order’, it ensured the Internet remained a level playing field for all.



However, in 2014, the court said the FCC lacked the authority to do so and enforce rules. This means, telecom companies who were earlier forced to follow the rules pf net neutrality started adopting unruly ways. This also paved way for ISPs to monitor data on their networks and also allowing governments to ban or block data. Besides banning or blocking data, we also jad the high profile Netflix-Comcast tussle.



Recently, FCC has approved “net neutrality” rules that prevent Internet providers such as Comcast and Verizon from slowing or blocking Web traffic or from creating Internet fast lanes that content providers such as Netflix must pay for. European Union member states have also been striving for net neutrality.


No more a thing of the west – Net neutrality in India


Taking the recent events into account, its time net neutrality is imposed in India too.



Since the past couple of years, the instances of Internet censorship in India have increased manifold. In 2011, India adopted the new ‘IT Rules 2011’ that supplemented the IT Act 2000. These rules made it mandatory for Internet intermediaries to remove objectionable content within 36 hours of receiving complaint. But the terms included were vague and open to interpretations. These rules received sharp criticism, but they have prevailed. In 2011, government also drew flak as it asked major sites like Google, Facebook and Yahoo to ‘pre-screen’ content and remove any objectionable, defamatory content from going live.Government requests for banning content has also been on rise over the past couple of years.

On the other hand, with the increasing popularity of instant messaging apps like WhatsApp, Viber and others, telcos had started making noise against the accelerated adoption of these services. Throughout last year, they’ve have been quite vocal about their dislike for over-the-top (OTT) services, who have been cannibalizing their main revenue streams – calls and SMSes.



There was buzz around a fee being imposed on popular OTT services, but the matter fizzled out soon after TRAI rejected telcos’ proposal to do so. In a bid to make up for the losing revenue, Airtel decided to play evil Santa on Christmas 2014 and announced an extra charge on making VoIP calls. The Twitterati had gone all out condeming Airtel for the act, and the service provider had to soon retract its decision. Net neutrality got yet another blow in India with the recent announcements from Reliance and Airtel.



In India, Facebook has teamed up with Reliance Communications in an effort to bring Internet.org to smartphone as well as feature phone users. But at the Mobile World Congress, telecom service providers such as Vodafone, Airtel and Telenor have made their discomfort clear when it comes to offering free Internet services over expensive telecom networks.



In order to compete with Reliance, Airtel announced Zero marketing platform allowing customers to access apps of participating app developers at zero data charges. Now, you may be wondering what is wrong if someone wants to offer free Internet? Free internet sounds tempting, but you need to be aware that you are only getting free access to services/apps which have struck a deal with the telcos. App developers and services who are flush with funds, will not find it an issue to pay telcos for data charges incurred by users. But this can leave app developers, specially start ups, who cannot afford Airtel or Reliance’s data rates at a definite disadvantage.



In India, the concept of net neutrality doesn’t exist legally. However, ISPs try to moderately not violate any laws. They’ve approached Trai for the losing revenues and are awaiting Trai’s decision on regulation IM app by OTT players. Most decisions here are made by DoT and Trai. However, it would be a good move to get things legally on paper, while Internet access in India is still at its infancy.



You can read the entire TRAI consultation paper here.

Source: Digit, FirstPost, netneutrality.in


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Tuesday, March 17, 2015

Network Topologies

 Sumit Kar     March 17, 2015     Networking     No comments   



What is a Topology?



The physical topology of a network refers to the configuration of cables, computers, and other peripherals.





Types:





  • Linear Bus





  • Ring





  • Star





  • Mesh





  • Tree





  • Intersecting Ring





  • Hybrid





  • Irregular






Point to Point



The simplest topology is a permanent link between two end points is point to point.. In this technology a separate connection is made between two communication channels.





Bus Topology 



Network Topologies






Bus Topology is the simplest of network topologies. In this type of topology, all the nodes (computers as well as servers) are connected to the single cable (called bus), by the help of interface connectors. This central cable is the backbone of the network and is known as Bus (thus the name). Every workstation communicates with the other device through this Bus. 





A signal from the source is broadcasted and it travels to all workstations connected to bus cable. Although the message is broadcasted but only the intended recipient, whose MAC address or IP address matches, accepts it. If the MAC /IP address of machine doesn’t match with the intended address, machine discards the signal. 





A terminator is added at ends of the central cable, to prevent bouncing of signals. A barrel connector can be used to extend it. Below I have given a basic diagram of a bus topology and then have discussed advantages and disadvantages of Bus Network Topology







Advantages:


1)  It is easy to set-up and extend bus network.


2)  Cable length required for this topology is the least compared to other networks.


3)  Bus topology costs very less.


4) Linear Bus network is mostly used in small networks. Good for LAN.





Disadvantages:


1)  There is a limit on central cable length and number of nodes that can be connected.


2)  Dependency on central cable in this topology has its disadvantages.If the main cable encounters some problem, whole network breaks down. 


3)  Proper termination is required to dump signals. Use of terminators is must.


4)  It is difficult to detect and troubleshoot fault at individual station.


5)  Maintenance costs can get higher with time.


6)  Efficiency of Bus network reduces, as the number of devices connected to it increases.


7)  It is not suitable for networks with heavy traffic. 


8)  Security is very low because all the computers receive the sent signal from the source.




Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

What is a Protocol?

 Sumit Kar     March 17, 2015     Networking     No comments   



A protocol is a set of rules that governs the data communications between computers on a network. In order for two computers to talk to each other, they must be speaking the same language.


It is an agreement that governs the procedure used to exchange information between two co-operating entities. The agreement usually includes how much information is to be sent, how often it is sent, how to recover transmission errors, who to receive the information etc.. In general, a protocol will include definition of message format, sequencing rules, concerning messages and interpretation rules concerning messages transferred in proper sequence.


Many different types of network protocols and standards are required to ensure that your computer (no matter which operating system, network card, or application you are using) can communicate with another computer located on the next desk or half-way around the world. The OSI (Open Systems Interconnection) Reference Model defines seven layers of networking protocols.


 













































OSI Layer


Name


Common Protocols


7


Application


HTTP |
FTP | SMTP | DNS | Telnet


6


Presentation


5


Session


4


Transport


TCP |
SPX


3


Network


IP |
IPX


2


Data
Link


Ethernet


1


Physical





 

 


 


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

What is a Network?

 Sumit Kar     March 17, 2015     Networking     No comments   



A computer network or data network is a telecommunications network which allows computers to exchange data. A network consists of two or more computers that are linked in order to share resources (such as printers and CDs), exchange files, or allow electronic communications. The computers on a network may be linked through cables, telephone lines, radio waves, satellites, or infrared light beams. Data is transferred in the form of packets. The connections between nodes are established using either cable media or wireless media. The best-known computer network is the Internet. 


Two very common types of networks include:



• Local Area Network (LAN)


• Wide Area Network (WAN)




There are also


  • Metropolitan Area Networks (MAN)

  • Wireless LAN (WLAN)

  • Wireless WAN (WWAN)

  • Campus Area Network, Controller Area Network, or sometimes Cluster Area Network (CAN)

  • Storage Area Network, System Area Network, Server Area Network or sometimes Small Area Network  (SAN)

  • Personal Area Network (PAN)

  • Desk Area Network (DAN) 



 



Local Area Network



A Local Area Network (LAN) is a network that is confined to a relatively small area. It is generally limited to a geographic area such as a writing lab, school, or building.


Wide Area Network



Wide Area Networks (WANs) connect networks in larger geographic areas, such as Kolkata, or India, or the world. Dedicated transoceanic cabling or satellite uplinks may be used to connect this type of global network.


 


Effectiveness of Networking




  • Delivery : Data communication ensures that Correct message should be delivered to recipient.






  • Accuracy : Data communication ensures that Accurate message must be delivered.






  • Timeliness : Data communication ensures that Message must be delivered within time.




Advantages




  • Scalability



  • Price by Performance



  • Resource Sharing



  • High Reliability



  • Video Conferencing  




Types of network Connections




  • Point to Point Connection (PtP) eg. LAN



  • Multipoint Connection eg. Hub




Direction of Data Flow




  • Simplex



  • Half Duplex



  • Full Duplex




Some Common Terms Related to Networking



•DNS - Domain Name System - translates network address (such as IP addresses) into terms understood by humans (such as Domain Names) and vice-versa

•DHCP - Dynamic Host Configuration Protocol - can automatically assign Internet addresses to computers and users

•FTP - File Transfer Protocol - a protocol that is used to transfer and manipulate files on the Internet

•HTTP - HyperText Transfer Protocol - An Internet-based protocol for sending and receiving webpages

•IMAP - Internet Message Access Protocol - A protocol for e-mail messages on the Internet

•IRC - Internet Relay Chat - a protocol used for Internet chat and other communications

•POP3 - Post Office protocol Version 3 - a protocol used by e-mail clients to retrieve messages from remote servers

•SMTP - Simple Mail Transfer Protocol - A protocol for e-mail messages on the Internet


 


 






Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp
Older Posts Home

Pages

  • Home

Trending Now

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Blog Archive

  • ▼  2020 (1)
    • ▼  May (1)
      • Automating your deployments using Ansible
  • ►  2015 (92)
    • ►  October (4)
    • ►  September (3)
    • ►  August (3)
    • ►  July (9)
    • ►  June (9)
    • ►  May (20)
    • ►  April (7)
    • ►  March (22)
    • ►  February (7)
    • ►  January (8)
  • ►  2014 (158)
    • ►  November (70)
    • ►  October (6)
    • ►  September (82)
Powered by Blogger.

Categories

C - Programming Java Programming Basic Technology 8085 Assembly Programming For Loop Numerical Methods WhatsApp Algorithm Shell Programming Programming Networking Windows Android C++ Programming CPP If Else Tricky Internet Microsoft Pattern Photography Socket Program News While Loop Array DBMS DS Macro Recursion User Defined Function Conditional Operator Data Structure Durga Puja Earthquake Google Mela Nokia SQL Share Yahoo Airtel Bio Command Prompt Confused Facebook Finance Firefox Ganges Graph HokKolorob Input Kolkata MCQ Math Matrix NetNeutrality Oracle Religion Search Sumit Kar Survey Switch Case Viral Virus Visual Studio do-while featured featured_slider

Popular Programs

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Daily Hits

Copyright © Sumit Kar