Re: Can a C function(server program) be a UDP or TCP server? - Mailing list pgsql-hackers

From Billow Gao
Subject Re: Can a C function(server program) be a UDP or TCP server?
Date
Msg-id 677a32120710180824x3d1c5b30r7eb76871ffb56565@mail.gmail.com
Whole thread Raw
In response to Can a C function(server program) be a UDP or TCP server?  ("Billow Gao" <billowgy@gmail.com>)
Responses Re: Can a C function(server program) be a UDP or TCP server?
List pgsql-hackers
On Thu, 18 Oct 2007 10:55:19 -0400<br />"Billow Gao" <<a href="mailto:billowgy@gmail.com">billowgy@gmail.com</a>>
wrote:<br/>> Is it possible to write a dynamic loaded C function as an UDP or TCP server? <br />><br />> What
wewant to do it is:<br />> Add a search function which send a UDP package to remote UDP server<br />> and then
listento an UDP port, waiting for the result.<br />> Ideally, we don't close the UDP server after the search query
end.<br />> So we can reuse it for next search.<br />><br />> Is it possible?<br /><br />>Short answer:
yes. Slightly longer answer: If you need to ask this<br />>quetion then you should really talk to someone about
network<br />>programming but this is the wrong list.<br /><br />Thanks for your reply.<br /><br />I can write the
networkprogram.<br />But I am not 100% sure whether I can add the c-language function (<a
href="http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html">
http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html</a>)<br/>to PostgreSQL. The function will be dynamic loaded
byPostgreSQL. <br />I want to know whether there are any limitation on the function I wrote.<br /><br />for example:
<br/>If I want to write a function: <br /><pre class="PROGRAMLISTING">PG_FUNCTION_INFO_V1(c_talktoremoteudp);</pre><br
/>Anduse it in PostgreSQL like:<br /><br />=========================================<br />SELECT name,
c_talktoremoteudp<br /><pre class="PROGRAMLISTING">(emp, 1500) AS overpaid<br />    FROM emp<br />    WHERE name =
'Bill'OR name = 'Sam';</pre>=========================================<br />The function c_talktoremoteudp will:<br />
1.send udp data to remote udp server<br />2. monitor an udp port and wait for the reply<br />3. return the data to the
selectquery.<br /><br />Anyway, I guess that it can be done. I will write a simple function to test it.<br /><br />
Ying<br/><br /><br />>If you are asking if PostgreSQL already does UDP then the answer is<br />>no.  You need to
writea server program that talks UDP in one direction<br />>and TCP to PostgreSQL in the other direction.  Watch out
forsecurity <br />>issues.  

pgsql-hackers by date:

Previous
From: "D'Arcy J.M. Cain"
Date:
Subject: Re: Can a C function(server program) be a UDP or TCP server?
Next
From: "D'Arcy J.M. Cain"
Date:
Subject: Re: Can a C function(server program) be a UDP or TCP server?