Re: UNIX domain sockets

From: Bruce James (bruce_at_pomegranate.ltd.uk)
Date: 11/02/03

  • Next message: Kasper Dziurdz: "Re: Get Windows Task-Names?!"
    Date: Sun, 02 Nov 2003 00:43:23 +0000
    
    

    Hi,
    Just out of interest, is /sckt writable? IE do you have permission to
    write to / ?
    Perhaps /tmp/sckt would be a better location.

    Good luck

    Bruce

    In article <3fa2ca69_2@127.0.0.1>, Jim Gibson
    <jgibson@mail.arc.nasa.gov> wrote:

    > Erik Anderson wrote:
    > > I'm trying to implement IPC using IO::Socket::UNIX, but have come into
    > > significant difficulty. I've searched groups.google.com, and have been
    > > able to find very few examples of the proper use of IO::Socket::UNIX.
    > >
    > > I have written a very simple client and server system to test this. The
    > > code is below. The client sends some data to the server, which should
    > > display it...it's not working though. Any ideas?
    >
    > As Tim Heany pointed out, the main problem is that you are not sending
    > any end-of-line characers from the client to the server, but the server
    > is waiting for an EOL before proceeding. I have some additional comments:
    >
    > >
    > > Client Code:
    > > --------------------
    > > #!/usr/bin/perl
    >
    > Always:
    >
    > use strict;
    >
    > >
    > > use IO::Handle;
    > > use IO::Socket;
    > >
    >
    > > $socket = IO::Socket::UNIX->new( Peer => "/sckt",
    > > Type => SOCK_STREAM,
    > > Timeout => 10 ) or die "$!\n$@";
    > >
    >
    > my $socket = ...
    >
    > > $socket->autoflush(1);
    >
    > Sockets are autoflush be default, but this line shouldn't hurt.
    >
    > >
    > > $num=0;
    >
    > my $num = 0;
    >
    > > while(1) {
    > > print $socket "$num";
    > > $socket->flush();
    > > $num++;
    > > sleep(2);
    > > }
    >
    > You are writing an infinite amount of data, but very slowly: 10
    > characters total in the first 20 seconds. Is your client ever going to
    > quit? Also, for consistency, use $socket->print():
    >
    > while( $num < 10 ) [
    > $socket->print("Line $num\n");
    > $socket->flush();
    > $num++;
    > sleep(2);
    > }
    >
    > >
    > > exit;
    >
    > No need to call exit as the last line in your program.
    >
    > > --------------------
    > >
    > > Server code:
    > > --------------------
    > > #!/usr/bin/perl
    > >
    > > use IO::Handle;
    > > use IO::Socket;
    > > unlink "/sckt";
    > > my $Server = IO::Socket::UNIX->new( Local => "/sckt",
    > > Type => SOCK_STREAM,
    > > Listen => 5
    > > ) or die $@;
    >
    > $@ contains the error for the last eval function call. You may want to
    > check $! instead.
    >
    > > while($session = $Server->accept) {
    > > chomp($line = <$session>);
    >
    > You are only reading one line from the client. You should put this in a
    > while loop and read until <$session> returns undef.
    >
    > > print "From client: " . $line . "\n";
    > > $Server->flush();
    >
    > There should be no need to flush the $Server socket. You are not writing
    > to this socket, and flushing an input buffer should rarely be done. You
    > may be dumping incoming data.
    >
    > >
    > > sleep(1);
    >
    > You may want to call $session->close() here -- I am not sure if it will
    > be closed automatically.
    >
    > > }
    > >
    > > exit;
    > > --------------------
    > >
    > > Thanks!
    > > -Erik Anderson
    > >
    >
    > If you really need to read and write data without line endings, you
    > should consider using syswrite and sysread instead of print and <>.
    >
    > I recommend getting and reading a copy of "Unix Network Programming,
    > Vol. 1", by W. Richard Stevens.
    >


  • Next message: Kasper Dziurdz: "Re: Get Windows Task-Names?!"

    Relevant Pages

    • Re: Socket switch delay
      ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
      (microsoft.public.win32.programmer.networks)
    • Re: Locking on async calls
      ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
      (microsoft.public.dotnet.general)
    • Re: socket communication: socket doesnt connect
      ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
      (microsoft.public.vc.language)
    • Re: TCP server stop receiving new connections
      ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
      (microsoft.public.win32.programmer.networks)
    • Re: Design issue with WinSock/GetQueuedCompletionStatus
      ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
      (microsoft.public.win32.programmer.networks)