socket connection - oracle11g

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

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;

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.

Related

VUE Front end to go server (http) and clients connected to go server (tcp) error

I'm currently creating a go TCP server that handles file sharing between multiple go clients, that works fine. However, I'm also building a front end using vue.js showing some server stats like the number of users, bytes sent, etc.
The problem occurs when I include the 'http.ListenAndServe(":3000", nil)' function handles the requests from the front end of the server. Is it impossible to have a TCP and an HTTP server on the same go file?
If so, how can a link the three (frontend, go-server, clients)
Here is the code of the 'server.go'
func main() {
// Create TCP server
serverConnection, error := net.Listen("tcp", ":8085")
// Check if an error occured
// Note: because 'go' forces you to use each variable you declare, error
// checking is not optional, and maybe that's good
if error != nil {
fmt.Println(error)
return
}
// Create server Hub
serverHb := newServerHub()
// Close the server just before the program ends
defer serverConnection.Close()
// Handle Front End requests
http.HandleFunc("/api/thumbnail", requestHandler)
fs := http.FileServer(http.Dir("../../tcp-server-frontend/dist"))
http.Handle("/", fs)
fmt.Println("Server listening on port 3000")
http.ListenAndServe(":3000", nil)
// Each client sends data, that data is received in the server by a client struct
// the client struct then sends the data, which is a request to a 'go' channel, which is similar to a queue
// Somehow this for loop runs only when a new connection is detected
for {
// Accept a new connection if a request is made
// serverConnection.Accept() blocks the for loop
// until a connection is accepted, then it blocks the for loop again!
connection, connectionError := serverConnection.Accept()
// Check if an error occurred
if connectionError != nil {
fmt.Println("1: Woah, there's a mistake here :/")
fmt.Println(connectionError)
fmt.Println("1: Woah, there's a mistake here :/")
// return
}
// Create new user
var client *Client = newClient(connection, "Unregistered_User", serverHb)
fmt.Println(client)
// Add client to serverHub
serverHb.addClient(client)
serverHb.listClients()
// go client.receiveFile()
go client.handleClientRequest()
}
}

pulling table with redis on lua

I'm running LUA on Nginx. I decided to fetch some variables via Redis. I am using a table on lua. It is like this;
local ip_blacklist = {
"1.1.1.1",
"1.1.1.2",
}
I'm printing on Nginx;
1.1.1.1
1.1.1.2
I want to keep the values here on Redis and not on Lua. My redis : http://prntscr.com/10sv3ln
My Lua command;
local ip = red:hmget("iplist", "ip_blacklist")
I'm printing on Nginx;
{"1.1.1.1","1.1.1.2",}
Its data does not come as a table and functions do not work. How can I call this data like local ip_blacklist?
https://redis.io/topics/data-types
Redis Hashes are maps between string fields and string values
You cannot store a Lua table as a hash value directly. As I understand, you have stored a literal string {"1.1.1.1","1.1.1.2",} using RedisInsight, but it doesn't work that way.
You can use JSON for serialization:
server {
location / {
content_by_lua_block {
local redis = require('resty.redis')
local json = require('cjson.safe')
local red = redis:new()
red:connect('127.0.0.1', 6379)
-- set a string with a JSON array as a hash value; you can use RedisInsight for this step
red:hset('iplist', 'ip_blacklist', '["1.1.1.1", "1.1.1.2"]')
-- read a hash value as a string (a serialized JSON array)
local ip_blacklist_json = red:hget('iplist', 'ip_blacklist')
-- decode the JSON array to a Lua table
local ip_blacklist = json.decode(ip_blacklist_json)
ngx.say(type(ip_blacklist))
for _, ip in ipairs(ip_blacklist) do
ngx.say(ip)
end
}
}
}
Output:
table
1.1.1.1
1.1.1.2

Ocaml / Async socket issue

I am quite new to OCaml and I am working on a small TCP client utility, using Async/Core.
The connection is opened using
Tcp.with_connection (Tcp.Where_to_connect.of_host_and_port { host = "localhost"; port = myPort })
I need to be able to accept keyboard input, as well as read input from the socket. I use the Deferred.any for this purpose.
Calling Reader.read reader buf on the socket results in `Eof, which is OK, but when the method (containing the Deferred.any code) is called recursively, I get an exception:
“unhandled exception in Async scheduler”
(“unhandled exception”
((monitor.ml.Error
(“can not read from reader” (reason “in use”)
.....
Reader.is_closed on the reader returns false.
How can I “monitor” the socket recursively without this exception?
Michael

Teradata and Java server Connection

I am trying to connect to JAVA server using Teradata UDF, here is my code below.It uses HOST as "localhost" and PORT(integer) as "9091" and all the parameters such as PEM file location etc have been provided, but the function always exits from the catch block.I know that exit(0) is not allowed in Teradata UDF's, I have used it just for the sake of debugging.The same code connects to the server absolutely fine in case ORACLE UDF. Please tell which ports can be used for communication in case of Teradata, or whether an SSL connection to server is even supported in Teradata.
The server accepts argument of type request and returns result ,both of type vector <struct>.
Response CplusplusClient::startClient(DeTokenizationRequest request) {
boost::shared_ptr<TSSLSocketFactory> factory(new TSSLSocketFactory());
factory->loadPrivateKey(PRIVATE_KEY.c_str());
factory->loadCertificate(CERTIFICATE.c_str());
factory->loadTrustedCertificates(TRUSTED_CERTIFICATE.c_str());
factory->authenticate(true);
boost::shared_ptr<TSSLSocket> socket = factory->createSocket(HOST,PORT);
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
XSecurityServiceClient client(protocol);
Response result;
try {
transport->open();
client.requested(result, request);
transport->close();
} catch (TException& tx) {
exit(0);
}
return result;
}
}
Changed the Port to 9092 and it worked

SQLAllocConnect success,but SQLConnect fail

I had made connector/ODBC successfully,then I write some code:
SQLHENV henv;
SQLHDBC phdbc;
SQLRETURN retcode;
retcode = SQLAllocEnv(&henv);
retcode = SQLAllocConnect(henv,&phdbc);
if(retcode == SQL_SUCCESS)
{
char *a="cc_mysql";
char *b="chen1991";
retcode = SQLConnect(phdbc,(SQLCHAR*)a,SQL_NTS,(SQLCHAR*)b,SQL_NTS,(SQLCHAR*)b,SQL_NTS);
}
but I failed to connect. I debug it and found that the SQLAllocConnect return true ,but SQLConnect return -1,I can't understand what happened.
What happened is your call to SQLConnect failed and you need to call SQLError to get the error back. I'd just be guessing but may be the DSN cc_mysql does not exist or your username/password are invalid, or mysql does not allow that user to access it etc.
BTW, you should really be writing at least ODBC 3 applications these days and to do that you should be calling SQLAllocHandle, SQLSetEnvAttr (to set ODBC behavior), SQLDriverConnect and SQLGetDiagRec.

Resources