h:hopen `:code.kx.com:80, doesn't seem to connect

I’ve read the help page on hopen but must be missing something. code.kx.com/q/ref/filewords/#hopen



hopen hangs until I press Ctrl-C, I’ve tried this with other webpages as well (ebay, google, etc.)


I would like to be able to issue multiple GET requests while the socket handle is open.


Any hints as to what I’m doing incorrectly?


/ this works

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

printf ‘GET /q/ HTTP/1.1\r\nHost: code.kx.com\r\nConnection: close\r\n\r\n’ | nc code.kx.com 80


/ here’s an example of what I would like to run on q.

h:hopen `:code.kx.com:80

h"GET /q/ HTTP/1.1\r\nHost: code.kx.com\r\nConnection: close\r\n\r\n"

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545}


p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

KDB+ 3.5 2017.11.30 Copyright (C) 1993-2017 Kx Systems

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

m32/ 4()core 8192MB x x x NONEXPIRE


)\ping code.kx.com

“PING code.kx.com (74.50.57.51): 56 data bytes”

“64 bytes from 74.50.57.51: icmp_seq=0 ttl=50 time=53.275 ms”

“64 bytes from 74.50.57.51: icmp_seq=1 ttl=50 time=61.843 ms”

“64 bytes from 74.50.57.51: icmp_seq=2 ttl=50 time=49.324 ms”

“”

“— code.kx.com ping statistics —”

“3 packets transmitted, 3 packets received, 0.0% packet loss”

“round-trip min/avg/max/stddev = 49.324/54.814/61.843/5.225 ms”


q)h:hopen `:code.kx.com:80 / wait 15 seconds then press ctrl-c

'hop. OS reports: Interrupted system call

[0] h:hopen `:code.kx.com:80 / wait 15 seconds then press ctrl-c

^

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

q)

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

I think you are confusing the URL format. What you type was effectively trying to log into to code.kx.com as a “kdb+ client” as user “80.”

If what you want to to use kdb+ as an HTTP client, please kindly refer to the cookbook here: http://code.kx.com/q/cookbook/programming-examples/

Thank you! That helped quite a bit for a single http request.
However, I would still like to see an example of keeping the TCP connection open for multiple requests.

-Anuj

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

q)s2s:“GET /go/AAPL.txt HTTP/1.0\r\nhost:goanuj.freeshell.org\r\n\r\n”

q)data:(`$“:http://goanuj.freeshell.org”) s2s

q)" " vs data

“HTTP/1.1”

“200”

“OK\r\nDate:”

“Tue,”

“19”

“Dec”

“2017”

“08:49:42”

“GMT\r\nServer:”

“Apache/2.2.34”

“(Unix)”

“mod_ssl/2.2.34”

“OpenSSL/1.0.2n\r\nLast-Modified:”

“Wed,”

“26”

“Jul”

“2017”

“06:02:15”

“GMT\r\nETag:”

“"43d0b205-d-5553230932625"\r\nAccept-Ranges:”

“bytes\r\nContent-Length:”

“13\r\nConnection:”

“close\r\nContent-Type:”

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

“text/plain\r\n\r\n"AAPL",17.92\n”

q)(4+data ss “\r\n\r\n”) _ data

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d0d2da; background-color: #161821; background-color: rgba(22, 24, 33, 0.95)}span.s1 {font-variant-ligatures: no-common-ligatures}

“"AAPL",17.92\n”

On Tuesday, December 19, 2017 at 12:09:31 AM UTC-8, Flying wrote:

I think you are confusing the URL format. What you type was effectively trying to log into to code.kx.com as a “kdb+ client” as user “80.”

If what you want to to use kdb+ as an HTTP client, please kindly refer to the cookbook here: http://code.kx.com/q/cookbook/programming-examples/

kdb+ is not a generic TCP client. You can keep websocket connections open, but I don’t think it’s possible with plain HTTP – HTTP itself is stateless anyway. Persistent HTTP connection is just a superficial add-on after all.

It’s fairly easy to call libcurl from kdb. I have no experience with C, but hacked together functions to make GET and POST requests while keeping the connection alive:

 

https://pastebin.mozilla.org/9075061

 

(Warning: it is most likely buggy. I just mashed together code examples I found on the web until it worked for my purposes of making rapid GET/POST requests.)

 

20.12.2017, 05:45, “Flying” <flying.oe@gmail.com>:

kdb+ is not a generic TCP client. You can keep websocket connections open, but I don’t think it’s possible with plain HTTP – HTTP itself is stateless anyway. Persistent HTTP connection is just a superficial add-on after all.

On Tuesday, December 19, 2017 at 5:12:46 PM UTC+8, ag wrote:

Thank you! That helped quite a bit for a single http request.
However, I would still like to see an example of keeping the TCP connection open for multiple requests.

-Anuj
 

q)s2s:“GET /go/AAPL.txt HTTP/1.0\r\nhost:goanuj.freeshell.org\r\n\r\n”

 

q)data:(`$“:http://goanuj.freeshell.org”) s2s

 

q)" " vs data

“HTTP/1.1”

“200”

“OK\r\nDate:”

“Tue,”

“19”

“Dec”

“2017”

“08:49:42”

“GMT\r\nServer:”

“Apache/2.2.34”

“(Unix)”

“mod_ssl/2.2.34”

“OpenSSL/1.0.2n\r\nLast-Modified:”

“Wed,”

“26”

“Jul”

“2017”

“06:02:15”

“GMT\r\nETag:”

“"43d0b205-d-5553230932625"\r\nAccept-Ranges:”

“bytes\r\nContent-Length:”

“13\r\nConnection:”

“close\r\nContent-Type:”

 

“text/plain\r\n\r\n"AAPL",17.92\n”

 

q)(4+data ss “\r\n\r\n”) _ data

 

“"AAPL",17.92\n”

On Tuesday, December 19, 2017 at 12:09:31 AM UTC-8, Flying wrote:

I think you are confusing the URL format. What you type was effectively trying to log into to code.kx.com as a “kdb+ client” as user “80.”
 

If what you want to to use kdb+ as an HTTP client, please kindly refer to the cookbook here: http://code.kx.com/q/cookbook/programming-examples/

On Tuesday, December 19, 2017 at 3:02:05 PM UTC+8, ag wrote:

I’ve read the help page on hopen but must be missing something. code.kx.com/q/ref/filewords/#hopen

 

hopen hangs until I press Ctrl-C, I’ve tried this with other webpages as well (ebay, google, etc.)

 

I would like to be able to issue multiple GET requests while the socket handle is open.

 

Any hints as to what I’m doing incorrectly?

 

/ this works

printf ‘GET /q/ HTTP/1.1\r\nHost: code.kx.com\r\nConnection: close\r\n\r\n’ | nc code.kx.com 80

 

/ here’s an example of what I would like to run on q.

h:hopen `:code.kx.com:80

h"GET /q/ HTTP/1.1\r\nHost: code.kx.com\r\nConnection: close\r\n\r\n"

 

KDB+ 3.5 2017.11.30 Copyright (C) 1993-2017 Kx Systems

 

m32/ 4()core 8192MB x x x NONEXPIRE

 

)\ping code.kx.com

“PING code.kx.com (74.50.57.51): 56 data bytes”

“64 bytes from 74.50.57.51: icmp_seq=0 ttl=50 time=53.275 ms”

“64 bytes from 74.50.57.51: icmp_seq=1 ttl=50 time=61.843 ms”

“64 bytes from 74.50.57.51: icmp_seq=2 ttl=50 time=49.324 ms”

“”

“— code.kx.com ping statistics —”

“3 packets transmitted, 3 packets received, 0.0% packet loss”

“round-trip min/avg/max/stddev = 49.324/54.814/61.843/5.225 ms”

 

q)h:hopen `:code.kx.com:80 / wait 15 seconds then press ctrl-c

'hop. OS reports: Interrupted system call

[0] h:hopen `:code.kx.com:80 / wait 15 seconds then press ctrl-c

^

 

q)

 


Submitted via Google Groups