Hi Thanks a lot for your reply !! It works!!

I am facing with another problem .I want to communicate between two process using sockets.One of those process is a C program(client) and another is a perl script(server).I am able to send messages from client, but some how I am unbale to recieve those messages at server side.

#include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include <stdio.h> #include <string.h> #define NSTRS 2 /* no. of strings */ #define ADDRESS "/tmp/temp_socket" /* addr to connect */ /* * Strings we send to the server. */ char *strs[NSTRS] = { "This is the second string from the client.\n", "This is the third string from the client.\n" }; int main() { char c; FILE *fp; register int i, s, len; struct sockaddr_un saun; /* * Get a socket to work with. This socket will * be in the UNIX domain, and will be a * stream socket. */ if ((s = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { perror("client: socket"); return(1); } /* * Create the address we will be connecting to. */ saun.sun_family = AF_UNIX; strcpy(saun.sun_path, ADDRESS); /* * Try to connect to the address. For this to * succeed, the server must already have bound * this address, and must have issued a listen() * request. * * The third argument indicates the "length" of * the structure, not just the length of the * socket name. */ len = sizeof(saun.sun_family) + strlen(saun.sun_path); if (connect(s, &saun, len) < 0) { perror("client: connect"); return(1); } /* * We'll use stdio for reading * the socket. */ fp = fdopen(s, "r"); /* * First we read some strings from the server * and print them out. */ /*for (i = 0; i < 1; i++) { while ((c = fgetc(fp)) != EOF) { putchar(c); if (c == '\n') break; } }*/ /* * Now we send some strings to the server. */ for (i = 0; i < NSTRS; i++) sendto(s, strs[i], strlen(strs[i]), 0,(struct sockaddr *)&saun +, sizeof(saun)); /* * We can simply use close() to terminate the * connection, since we're done with both sides. */ close(s); return(0); } Server(perl script) : #!/usr/bin/perl -w use strict; use IO::Socket::UNIX; # simple server use IO::Handle; unlink "/tmp/temp_socke"; our $server = IO::Socket::UNIX->new(Local => "/tmp/temp_socke", Type => SOCK_DGRAM, Listen => 5) or die $ !; print "I am here\n"; my $wanted = 1024; my $buff; while ($server->recv($buff, $wanted)) { print "$buff"; } close ($server); exit(0);
Please correct me where I am going wrong ? Thanks Zebith

In reply to Re^2: problem with UNIX Domain sockets by zenith007
in thread problem with UNIX Domain sockets by zenith007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.