Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it just me or is there a certian incompatibility in the local socket model (which I am just learning on linux) between perl and c?

If I use a normative perl server (which sets up it's own socket to recieve requests) with a normative c client (which sets up it's own named, bound socket, then requests a connect to another), I get a working connection.

BUT if I use a normative c server (which acts like a perl server, I believe) with a normative perl client (which sets up an anonymous, unbound socket, then requests a connect to another), the server accepts the request but there is no working connection (or the request bounces).

I'm not quiet sure why this is other that the fact that you don't have to bind a local socket in perl in order to connect it. Does anyone familiar with the phenomenon have any suggestions about how to circumvent it?

Replies are listed 'Best First'.
Re: Local socket model
by ikegami (Patriarch) on Oct 07, 2008 at 12:21 UTC
    Sorry, but Perl clients have no problem connecting to C servers, which is no surprise because Perl sockets functions are just extremely thin interfaces to the C socket functions.
Re: Local socket model
by Illuminatus (Curate) on Oct 07, 2008 at 12:47 UTC
    Does your 'normative perl client' only fail when trying to connect to your C server example and not your perl server example? Have you tried this? Are you using the built-in socket/connect/etc calls, or IO::Socket? Perhaps posting a short code sample would help.
      hmmm...bad news for me then. The perl client is simple. It doesn't use IO::Socket.
      #!/usr/bin/perl -w use strict; # simple client use Socket; use IO::Handle; socket(TSOCK, PF_UNIX, SOCK_STREAM,0); connect(TSOCK, sockaddr_un("/tmp/testsock")) or print "ERROR!"; while (defined(my $messg = <TSOCK>)) { print $messg; print TSOCK "Hello server!\n"; TSOCK->flush; }
      Both servers work fine with their counter-part (but I wrote them to do that). I haven't tried to change anything to debug the "c<->perl" problem, because I have a hard time understanding what could be wrong (they are just exchanging strings) and thought I would ask here to find out if there is something I'm unaware of.

      If I connect the above perl client to the c server, it accepts a new connection, but it does not recieve the "Hello", and the client does not recieve messages from the server.

      What could go wrong, considering the c server works fine with connections to other c programs?
        What string does the C server send after it accepts the connection? It does have a newline in it, right?