Re: Can a C function(server program) be a UDP or TCP server?

From: "Billow Gao" <billowgy(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Can a C function(server program) be a UDP or TCP server?
Date: 2007-10-18 15:24:24
Message-ID: 677a32120710180824x3d1c5b30r7eb76871ffb56565@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 18 Oct 2007 10:55:19 -0400
"Billow Gao" <billowgy(at)gmail(dot)com> wrote:
> Is it possible to write a dynamic loaded C function as an UDP or TCP
server?
>
> What we want to do it is:
> Add a search function which send a UDP package to remote UDP server
> and then listen to an UDP port, waiting for the result.
> Ideally, we don't close the UDP server after the search query end.
> So we can reuse it for next search.
>
> Is it possible?

>Short answer: yes. Slightly longer answer: If you need to ask this
>quetion then you should really talk to someone about network
>programming but this is the wrong list.

Thanks for your reply.

I can write the network program.
But I am not 100% sure whether I can add the c-language function (
http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html)
to PostgreSQL. The function will be dynamic loaded by PostgreSQL.
I want to know whether there are any limitation on the function I wrote.

for example:
If I want to write a function:

PG_FUNCTION_INFO_V1(c_talktoremoteudp);

And use it in PostgreSQL like:

=========================================
SELECT name, c_talktoremoteudp

(emp, 1500) AS overpaid
FROM emp
WHERE name = 'Bill' OR name = 'Sam';

=========================================
The function c_talktoremoteudp will:
1. send udp data to remote udp server
2. monitor an udp port and wait for the reply
3. return the data to the select query.

Anyway, I guess that it can be done. I will write a simple function to test
it.

Ying

>If you are asking if PostgreSQL already does UDP then the answer is
>no. You need to write a server program that talks UDP in one direction
>and TCP to PostgreSQL in the other direction. Watch out for security
>issues.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message D'Arcy J.M. Cain 2007-10-18 15:53:23 Re: Can a C function(server program) be a UDP or TCP server?
Previous Message D'Arcy J.M. Cain 2007-10-18 15:13:25 Re: Can a C function(server program) be a UDP or TCP server?