LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

http web client labwindows CVI

I am looking for a sample program (or ideas) to send and receive HTTP to a specified port in Labwindows CVI.  There are examples for FTP and Telenet.  Their Client and Server examples only talk to eachother.

 

In a browser, I can type "http://<address>:<port#>/get?OID4.1="  The device I wish to talk to then responds.  How do I do this in CVI?  Thanks for your help.

0 Kudos
Message 1 of 6
(6,482 Views)
Your application will to communicate via tcp http://zone.ni.com/reference/en-XX/help/370051P-01/cvi/libref/cvitcp_library/ . Most likely as a server http://zone.ni.com/reference/en-XX/help/370051K-01/cvi/cviregistertcpserver/ . Depending on your application you may be able to use datasockets: C:\Documents and Settings\All Users\Documents\National Instruments\CVI2009\samples\datasocket . If you're looking for a full fledged web server you may need to look into another library.
Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand
0 Kudos
Message 2 of 6
(6,447 Views)

Thanks for the response.  I looked through the documents and I think I am getting hung up on the term "server" and "connection" since I thought that HTTP was connectionless. 

 

To recap:

 

in my Browser, I type the URL http://192.168.0.150:85/get?OID4.1.13=

 

I get an immediate response string "OID4.1.13=693&"

 

This implies that I am the client and there is no specific connection made.

 

I think this is simpler then I am making it to be.

 

Thanks, 

Dave

0 Kudos
Message 3 of 6
(6,439 Views)

You can use the telnet libraries to have a CVI application talk to a web server.  You just have to connect to the server on port 80 using InetTelnetOpen().  You then have to send the proper commands to have the server respond using InetTelnetWrite(), like so

GET http://www.example.com/index.html HTTP/1.1Host: example.com

The server will then respond with the webpage you requested then close the connection.  You'll have to strip out some header information manually.  The only trick is when you read back the response, it will time out unless you can trigger off something in the response to know that it has reached the end.  You can use InetTelnetReadUntil() with "</html>" as the string to match in many cases.

Hope this helps.

Message 4 of 6
(6,413 Views)

InetTelnerOpen does not work, always returns a handel of 0.  My understanding (after research) is that InetTelnerOpen needs to connect with (handshake with) a Telnet server on that port.  My application is HTTP, not Telnet.  HTTP to my understanding is connectionless, that is, handshaling is required with the target device.

 

Again, I suspect this is simpler then I am making this out to be.

 

Anyone have any Ideas?

 

Thanks!

0 Kudos
Message 5 of 6
(6,338 Views)

You should be okay.  For some reason, a handle of 0 is valid with InetTelnetOpen(), which I know is different from every other CVI library function, but that's the way it is.

If you want, you can try it out using the telnet client in Windows:

telnet <host> 80

You have to type very carefully because the server won't echo back (you can't see what you're doing).  Or just type some garbage and push enter, and the server will probably respond with a HTTP/1.1 400 Bad Request.

0 Kudos
Message 6 of 6
(6,334 Views)