cancel
Showing results for 
Search instead for 
Did you mean: 

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

ag1
New Contributor
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)

4 REPLIES 4

Flying
New Contributor III
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/

ag1
New Contributor
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/

Flying
New Contributor III
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:
 
 
(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)

 

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at https://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.