Re: berkley sockets - Mailing list pgsql-general

From J S B
Subject Re: berkley sockets
Date
Msg-id a47902760609131740o51e146ceq73e3fd1b13f9741a@mail.gmail.com
Whole thread Raw
In response to Re: berkley sockets  (Tony Caduto <tony_caduto@amsoftwaredesign.com>)
Responses Re: berkley sockets
List pgsql-general
Thanks alot Tony.
just wondering if the same can be done with C
~Jas

 
On 9/13/06, Tony Caduto <tony_caduto@amsoftwaredesign.com> wrote:
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: ljb
Date:
Subject: Re: remote duplicate rows
Next
From: Ron Johnson
Date:
Subject: Re: remote duplicate rows