Re: berkley sockets - Mailing list pgsql-general

From Tony Caduto
Subject Re: berkley sockets
Date
Msg-id 450874D6.3090706@amsoftwaredesign.com
Whole thread Raw
In response to Re: berkley sockets  ("J S B" <jsbali@gmail.com>)
Responses Re: berkley sockets  ("J S B" <jsbali@gmail.com>)
List pgsql-general
J S B wrote:
> I don't want to connect to the postgres database.
>
> The scenario is something like this.
>
> Postgres database has to initiate some deamon process running is
> another server.
> The only way i could think of doing this was openeing a socket
> connection between postgres database and
> the deamon process through a shared object dynamicall loaded in postgres.
>
> Berkley sockets is the socket API in unix that uses
> <sys/socket.h>
>
> Don't know if there's a better way to do it.
>
> ~Jas
>
I have done this using PLperl  (untrusted) and it works just fine.
Here is a simple example that just sends a command to a popup
notification daemon I use.

Win32 clients connect to the daemon and when I need to notify them of
incoming files from a ProFTP server I use this function.
Works great and have never had a problem.

CREATE or REPLACE FUNCTION public.psendpopup(
text,
text)
RETURNS pg_catalog.varchar AS
$BODY$
use IO::Socket;
$sock = new IO::Socket::INET (
                              PeerAddr => 'localhost',
                              PeerPort => '13000',
                              Proto => 'tcp',
                              );
die "Could not create socket: $!\n" unless $sock;
print $sock "null\r\n";
print $sock "send_broadcast\r\n";
print $sock $_[0]."\r\n";
print $sock $_[1]."\r\n";

close($sock);
$BODY$
LANGUAGE 'plperlu' VOLATILE;



--
Tony Caduto
AM Software Design
http://www.amsoftwaredesign.com
Home of PG Lightning Admin for Postgresql
Your best bet for Postgresql Administration


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Kill specific connection
Next
From: Steve Crawford
Date:
Subject: Re: Kill specific connection