Socket Problem............

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Clement

    #1

    Socket Problem............

    Please help me.......
    I am getting blocked in bind() system call.......

    i don't know why

    can you please any one tell me why........


    #include<stdio. h>
    #include<sys/un.h>
    #include<sys/types.h>
    #include<sys/socket.h>
    #define SOCK_PATH "mysock1"
    void error(char *);
    main()
    {
    printf("OK");
    int sockfd,newsockf d,serverlen,cli len,n;
    struct sockaddr_un cli_addr,serv_a ddr;
    char buf[80];
    printf("Ok");
    if((sockfd=sock et(AF_UNIX,SOCK _STREAM,0))<0)
    perror("creatin g socket");
    serv_addr.sun_f amily=AF_UNIX;
    printf("OK");
    unlink(SOCK_PAT H);
    strcpy(serv_add r.sun_path,SOCK _PATH);
    if(bind(sockfd, (struct sockaddr
    *)&serv_addr,si zeof(serv_addr) )<0)
    perror("binding socket");
    listen(sockfd,1 );
    clilen=sizeof(c li_addr);
    newsockfd=accep t(sockfd,(struc t sockaddr
    *)&cli_addr,&cl ilen);
    printf("Ok\n");
    if(newsockfd<0)
    error("acceptin g");
    for(;;)
    {
    printf("Waiting for Client......\n" );
    read(newsockfd, buf,sizeof(buf) );
    printf("**CLIEN T** :%s",buf);
    if(strcmp("end\ n",buf)==0)
    {
    printf("Disconn ecting\n");
    exit(0);
    }
    printf("**SERVE R** :");
    fgets(buf,sizeo f(buf),stdin);
    write(newsockfd ,buf,sizeof(buf ));
    }
    }
    void error(char *msg)
    {
    perror(msg);
    exit(0);
    }

  • santosh

    #2
    Re: Socket Problem........ ....

    Clement wrote:
    Please help me.......
    I am getting blocked in bind() system call.......
    >
    i don't know why
    >
    can you please any one tell me why........
    <snip>

    Since bind() is not defined by ISO C, you should try a group specific to
    your system, most likely <comp.unix.prog rammer>

    Comment

    • husterk

      #3
      Re: Socket Problem........ ....

      On Oct 19, 2:12 pm, Clement <jeba.r...@gmai l.comwrote:
      Please help me.......
      I am getting blocked in bind() system call.......
      >
      i don't know why
      >
      can you please any one tell me why........
      >
      #include<stdio. h>
      #include<sys/un.h>
      #include<sys/types.h>
      #include<sys/socket.h>
      #define SOCK_PATH "mysock1"
      void error(char *);
      main()
      {
      printf("OK");
      int sockfd,newsockf d,serverlen,cli len,n;
      struct sockaddr_un cli_addr,serv_a ddr;
      char buf[80];
      printf("Ok");
      if((sockfd=sock et(AF_UNIX,SOCK _STREAM,0))<0)
      perror("creatin g socket");
      serv_addr.sun_f amily=AF_UNIX;
      printf("OK");
      unlink(SOCK_PAT H);
      strcpy(serv_add r.sun_path,SOCK _PATH);
      if(bind(sockfd, (struct sockaddr
      *)&serv_addr,si zeof(serv_addr) )<0)
      perror("binding socket");
      listen(sockfd,1 );
      clilen=sizeof(c li_addr);
      newsockfd=accep t(sockfd,(struc t sockaddr
      *)&cli_addr,&cl ilen);
      printf("Ok\n");
      if(newsockfd<0)
      error("acceptin g");
      for(;;)
      {
      printf("Waiting for Client......\n" );
      read(newsockfd, buf,sizeof(buf) );
      printf("**CLIEN T** :%s",buf);
      if(strcmp("end\ n",buf)==0)
      {
      printf("Disconn ecting\n");
      exit(0);
      }
      printf("**SERVE R** :");
      fgets(buf,sizeo f(buf),stdin);
      write(newsockfd ,buf,sizeof(buf ));
      }}
      >
      void error(char *msg)
      {
      perror(msg);
      exit(0);
      >
      >
      >
      }- Hide quoted text -
      >
      - Show quoted text -
      Try configuring your socket for non-blocking (i.e. asynchronous)
      operation prior to calling the bind function. This will allow you to
      place a timeout on the bind() call which will return some type of
      error code instead of just hanging your system. You can then review
      this error code to determine what the problem is. Don't forget to
      change the socket back to blocking.

      Keith


      Comment

      • CBFalconer

        #4
        Re: Socket Problem........ ....

        Clement wrote:
        >
        I am getting blocked in bind() system call.......
        i don't know why
        can you please any one tell me why........
        >
        #include<stdio. h>
        #include<sys/un.h>
        #include<sys/types.h>
        #include<sys/socket.h>
        So far the only thing mentioned that exists in standard C is
        <stdio.h>. Try a newsgroup that deals with your particular
        system.

        --
        Chuck F (cbfalconer at maineline dot net)
        Available for consulting/temporary embedded and systems.
        <http://cbfalconer.home .att.net>



        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        Working...