0

Hey can u tell me what sock_path is in unix.

I am getting totally confused...i am getting an error " Socket operation on non-socket".

Does this path hold the structure we define and where to store the structure!! I have posted my entire client side code.

I am getting the same error on both sides(client and server)...please help...i dont get sock_path part??

#define SOCK_PATH "echo_socket" 

int main(void) 
{
    int s, t, len;  
    struct sockaddr_un remote;  
    char str[100];  

    if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { 
        perror("socket");  exit(1); 
    } 

    printf("Trying to connect...\n");  
    remote.sun_family = AF_UNIX;  

    strcpy(remote.sun_path, SOCK_PATH);  
    len = strlen(remote.sun_path) + sizeof(remote.sun_family);   

    int val=connect(s, (struct sockaddr *)&remote, len);   
    if ( val< 0) {
       perror("connect");  
       exit(1);
    }

    printf("Connected.\n");  

    while(printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
       if (send(s, str, strlen(str), 0) == -1) {
          perror("send"); 
          exit(1); 
       }

       if ((t=recv(s, str, 100, 0)) > 0) { 
          str[t] = '\0';  
          printf("echo> %s", str);
       } else {
          if (t < 0) perror("recv");  
          else printf("Server closed connection\n");   
          exit(1);
       }
    }
 }
4

1 に答える 1

0

Are you trying to use unix socket for file operations? If yes, SOCK_PATH which you assign to sun_path should be a file name.

Have a look at this.. http://beej.us/guide/bgipc/output/html/multipage/unixsock.html

于 2012-07-12T18:41:38.060 に答える