This is a discussion on berkley sockets within the Pgsql General forums, part of the PostgreSQL category; --> Hi, Just wondering if anyone has used Berkley sockets ever. I'm aiming at establishing a socket connection between my ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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----- |
| |||
| 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----- > > > |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| |||
| 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 > > |
| |||
| 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+Mau0tcUx bpLCq/8QCggrUB tvdsApAfzssoB0v6qdaS/rM= =9EJP -----END PGP SIGNATURE----- |
| |||
| 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+Mau0tcUx bpLCq/8QCggrUB > tvdsApAfzssoB0v6qdaS/rM= > =9EJP > -----END PGP SIGNATURE----- > > > |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| ||||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly |