Sunday, February 12, 2012

Listen , bind , socket network lab


Listen 
#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<unistd.h>
#include<netinet/in.h>
int main()
{
 int sockd1,s,l;
 struct sockaddr_in p;
 sockd1=socket(AF_INET,SOCK_STREAM,0);
 if(sockd1==-1)
  {
   printf("Sockect wasn't created\n");
  }
 else
  {
   printf("socket was perfectly created with value %d\n",sockd1);
   s=bind(sockd1,(struct sockaddr*) &p,sizeof(struct sockaddr));
   if(s==-1)
   printf("bind wasn't done\n");
   else
   {
   printf("bind was done\n");
   l=listen(sockd1,1);
   if(l==-1)
     printf("not listening\n");
   else
    printf("Server is listening\n");
  }
}
 close(sockd1);
 return(0);

No comments:

Post a Comment