socket connection

二次信任 提交于 2019-12-12 01:15:19

问题


I would like to send a string via a socket to an external display unit via the oracle 11g database I gather that the character or string first has to be converted to hex and at the end of the string a checksum must be addead (to validate the string to be sent)

Can anyone tell me how a socket connection can be opened and a string can be sent?

Thank you


回答1:


DECLARE
   bt_conn      UTL_TCP.connection;
   retval       BINARY_INTEGER;
   l_sequence   VARCHAR2 (50) := '@0100010303000118000201001401000201'; --string to be sent
BEGIN
   bt_conn :=
      UTL_TCP.open_connection (remote_host   => '127.0.0.1', --IP of socket to be opened 
                               remote_port   => 26665, -- port number of socket
                               tx_timeout    => 15);
   DBMS_LOCK.SLEEP(1); -- this is to ensure a slight pause once opening the connection before  --sending the string
   retval := UTL_TCP.write_line (bt_conn, l_sequence);
   UTL_TCP.flush (bt_conn);
   UTL_TCP.close_connection (bt_conn);
EXCEPTION
   WHEN OTHERS
   THEN
      raise_application_error (-20101, SQLERRM);
      UTL_TCP.close_connection (bt_conn);
end;



回答2:


Theoretically you can achieve this by using Java stored procedure - if you grant yourself priv to open a TCP socket from Oracle JVM. But this way the data will be sent regardless on transaction result(commit or rollback). The better solution would to store those strings in some queue table and then withdraw them using some external process.

You can also use DBMS_PIPE.



来源:https://stackoverflow.com/questions/14767938/socket-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!