On Oct 19, 2:12 pm, Clement <jeba.r...@gmail.com> wrote:
> Please 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,newsockfd,serverlen,clilen,n;
> struct sockaddr_un cli_addr,serv_addr;
> char buf[80];
> printf("Ok");
> if((sockfd=socket(AF_UNIX,SOCK_STREAM,0))<0)
> perror("creating socket");
> serv_addr.sun_family=AF_UNIX;
> printf("OK");
> unlink(SOCK_PATH);
> strcpy(serv_addr.sun_path,SOCK_PATH);
> if(bind(sockfd,(struct sockaddr
> *)&serv_addr,sizeof(serv_addr))<0)
> perror("binding socket");
> listen(sockfd,1);
> clilen=sizeof(cli_addr);
> newsockfd=accept(sockfd,(struct sockaddr
> *)&cli_addr,&clilen);
> printf("Ok\n");
> if(newsockfd<0)
> error("accepting");
> for(;
> {
> printf("Waiting for Client......\n");
> read(newsockfd,buf,sizeof(buf));
> printf("**CLIENT** :%s",buf);
> if(strcmp("end\n",buf)==0)
> {
> printf("Disconnecting\n");
> exit(0);
> }
> printf("**SERVER** :");
> fgets(buf,sizeof(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
http://www.doubleblackdesign.com