Thread: berkley sockets

berkley sockets

From
"J S B"
Date:
Hi,
Just wondering if anyone has used Berkley sockets ever.
I'm aiming at establishing a socket connection between my Postgres database server (using the shared objects that i dynamically load)
and a Unix server.
What would be the best thing to use for such a thing in Postgres scenario?
 
Thanks,
 
~Jas

Re: berkley sockets

From
Martijn van Oosterhout
Date:
On Tue, Sep 12, 2006 at 07:52:08PM -0400, J S B wrote:
> Hi,
> Just wondering if anyone has used Berkley sockets ever.
> I'm aiming at establishing a socket connection between my Postgres database
> server (using the shared objects that i dynamically load)
> and a Unix server.
> What would be the best thing to use for such a thing in Postgres scenario?

You mean you want to connect to a postgres database? For C you'd use
libpq, but it really depends on what language you're using. Or do you
want the server to connect somewhere, or what?

What exactly would you classify under "berkley sockets" anyway?

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

Re: berkley sockets

From
"J S B"
Date:
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

 
On 9/13/06, Martijn van Oosterhout <kleptog@svana.org> wrote:
On Tue, Sep 12, 2006 at 07:52:08PM -0400, J S B wrote:
> Hi,
> Just wondering if anyone has used Berkley sockets ever.
> I'm aiming at establishing a socket connection between my Postgres database
> server (using the shared objects that i dynamically load)
> and a Unix server.
> What would be the best thing to use for such a thing in Postgres scenario?

You mean you want to connect to a postgres database? For C you'd use
libpq, but it really depends on what language you're using. Or do you
want the server to connect somewhere, or what?

What exactly would you classify under "berkley sockets" anyway?

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFB5ecIB7bNG8LQkwRArlLAJ9O46fPvZ1f+BDP3vwmr+n6DbVumgCePzVp
XXqhFx9NPs5sAO7D+/bMFKI=
=JbS7
-----END PGP SIGNATURE-----



Re: berkley sockets

From
Chris Mair
Date:
On Wed, 2006-09-13 at 01:51 -0400, 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.

Is ist that you want to have a PG instance running on host A accepting
connections on host B?

Maybe you can use an SSH tunnel?

Bye, Chris.



--

Chris Mair
http://www.1006.org


Re: berkley sockets

From
Tony Caduto
Date:
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


Re: berkley sockets

From
"J S B"
Date:
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


Re: berkley sockets

From
Martijn van Oosterhout
Date:
On Wed, Sep 13, 2006 at 08:40:24PM -0400, J S B wrote:
> Thanks alot Tony.
> just wondering if the same can be done with C

Not entirely clear what you're doing, but couldn't you do what you want
with LISTEN/NOTIFY. That way the daemon connects to the server too and
get notified when other clients request it...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

Re: berkley sockets

From
"J S B"
Date:
What exactly is this LISTEN/NOTIFY?
Is it some function in socket programing or some part of postgres?

~Jas

On 9/15/06, Martijn van Oosterhout <kleptog@svana.org> wrote:
On Wed, Sep 13, 2006 at 08:40:24PM -0400, J S B wrote:
> Thanks alot Tony.
> just wondering if the same can be done with C

Not entirely clear what you're doing, but couldn't you do what you want
with LISTEN/NOTIFY. That way the daemon connects to the server too and
get notified when other clients request it...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFCm1nIB7bNG8LQkwRAqNhAKCI5xSGEQr0l+Mau0tcUxbpLCq/8QCggrUB
tvdsApAfzssoB0v6qdaS/rM=
=9EJP
-----END PGP SIGNATURE-----



Re: berkley sockets

From
Tony Caduto
Date:
J S B wrote:
> What exactly is this LISTEN/NOTIFY?
> Is it some function in socket programing or some part of postgres?
>
> ~Jas
>
Listen/Notify is a means of letting a connected postgresql client know a
insert or other event has occurred.
It won't help if you need to send a command/message to some other tcp/ip
daemon.

You set up a rule to use Notify:

create rule InsertDetect as on INSERT to notify_test do notify recinsert

Then on the client side (if the client has libpq listen capability) you
listen for the incoming notification messages and react to them
accordingly.

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


Re: berkley sockets

From
Tony Caduto
Date:
On Wed, Sep 13, 2006 at 08:40:24PM -0400, J S B wrote:
>> Thanks alot Tony.
>> just wondering if the same can be done with C
>>
If you are more comfortable with C, I don't see why you couldn't do the
same thing as that PLperl function.
It's just a matter of creating a socket and sending a string with a
CRLF, and then if the command you send returns anything you just go into
a blocking
read until you get the response back.

Later,

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