OPENCLIENT: Difference between revisions
Jump to navigation
Jump to search
NOTE: Try a valid TCP/IP port setting to test this routine!
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
m (missing & from variable name h&) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
The | {{DISPLAYTITLE:_OPENCLIENT}} | ||
The '''_OPENCLIENT''' function connects to a Host on the Internet as a Client and returns the Client status handle. | |||
{{Text|'''HTTP functionality is current unstable, and requires [[$UNSTABLE]]:HTTP to be able to use.'''|red}} | |||
{{PageSyntax}} | {{PageSyntax}} | ||
:{{Parameter|clientHandle&}} = [[_OPENCLIENT]]('''"TCP/IP:8080:12:30:1:10"''') | :{{Parameter|clientHandle&}} = [[_OPENCLIENT]]('''"TCP/IP:8080:12:30:1:10"''') | ||
:{{Parameter|clientHandle&}} = [[_OPENCLIENT]]('''"HTTP:url"''') | |||
Line 10: | Line 14: | ||
*Connects to a host somewhere on the internet as a client. | *Connects to a host somewhere on the internet as a client. | ||
*Valid {{Parameter|clientHandle&}} values are negative. 0 means that the connection failed. Always check that the handle returned is not 0. | *Valid {{Parameter|clientHandle&}} values are negative. 0 means that the connection failed. Always check that the handle returned is not 0. | ||
*[[CLOSE]] | *[[CLOSE]] {{Parameter|clientHandle&}} closes the client. A failed handle of value 0 does not need to be closed. | ||
{{PageExamples}} | {{PageExamples}} | ||
;Example 1:Attempting to connect to a local host(your host) as a client. A zero return indicates failure. | |||
{{CodeStart}} | {{CodeStart}} | ||
client = {{Cl|_OPENCLIENT}}("TCP/IP:7319:localhost") | client = {{Cl|_OPENCLIENT}}("TCP/IP:7319:localhost") | ||
{{Cl|IF...THEN|IF}} client {{Cl|THEN}} | {{Cl|IF...THEN|IF}} client {{Cl|THEN}} | ||
{{Cl|PRINT}} "[Connected to " + {{Cl|_CONNECTIONADDRESS}}(client) + "]" | {{Cl|PRINT}} "[Connected to " + {{Cl|_CONNECTIONADDRESS}}(client) + "]" | ||
{{Cl|ELSE}} {{Cl|PRINT}} "[Connection Failed!]" | {{Cl|ELSE}} {{Cl|PRINT}} "[Connection Failed!]" | ||
{{Cl|END IF}} | {{Cl|END IF}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
<center>'''NOTE:''' Try a valid TCP/IP port setting to test this routine!</center> | |||
---- | |||
;Example 2:Using HTTP to download from a URL. | |||
{{CodeStart}} | {{CodeStart}} | ||
' | ' Content of the HTTP response is returned. The statusCode is also assigned. | ||
{{Cl| | {{Cl|FUNCTION}} Download$(url {{Cl|AS}} {{Cl|STRING}}, statusCode {{Cl|AS}} {{Cl|LONG}}) | ||
h& = {{Cl|_OPENCLIENT}}("HTTP:" + url) | |||
{{Cl| | |||
{{Cl| | statusCode = {{Cl|_STATUSCODE}}(h&) | ||
{{Cl| | |||
{{Cl| | {{Cl|WHILE}} {{Cl|NOT}} {{Cl|EOF}}(h&) | ||
{{Cl|_LIMIT}} 60 | |||
{{Cl|GET (HTTP statement)|GET}} #h&, , s$ | |||
content$ = content$ + s$ | |||
{{Cl|WEND}} | |||
{{Cl|CLOSE}} #h& | |||
Download$ = content$ | |||
{{Cl|END FUNCTION}} | {{Cl|END FUNCTION}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Line 81: | Line 52: | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
*[[_OPENHOST]], [[_OPENCONNECTION]] | * [[_OPENHOST]], [[_OPENCONNECTION]] | ||
*[[_CONNECTED]], [[_CONNECTIONADDRESS$]] | * [[_CONNECTED]], [[_CONNECTIONADDRESS$]] | ||
*[[Email Demo]], [[Inter-Program Data Sharing Demo]] | * [[Email Demo]], [[Inter-Program Data Sharing Demo]] | ||
*[[Downloading Files]] | * [[Downloading Files]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 17:58, 20 February 2023
The _OPENCLIENT function connects to a Host on the Internet as a Client and returns the Client status handle.
HTTP functionality is current unstable, and requires $UNSTABLE:HTTP to be able to use.
Syntax
- clientHandle& = _OPENCLIENT("TCP/IP:8080:12:30:1:10")
- clientHandle& = _OPENCLIENT("HTTP:url")
Description
- An Illegal Function Call error will be triggered if the function is called with a string argument of the wrong syntax.
- Connects to a host somewhere on the internet as a client.
- Valid clientHandle& values are negative. 0 means that the connection failed. Always check that the handle returned is not 0.
- CLOSE clientHandle& closes the client. A failed handle of value 0 does not need to be closed.
Examples
- Example 1
- Attempting to connect to a local host(your host) as a client. A zero return indicates failure.
client = _OPENCLIENT("TCP/IP:7319:localhost") IF client THEN PRINT "[Connected to " + _CONNECTIONADDRESS(client) + "]" ELSE PRINT "[Connection Failed!]" END IF |
- Example 2
- Using HTTP to download from a URL.
' Content of the HTTP response is returned. The statusCode is also assigned. FUNCTION Download$(url AS STRING, statusCode AS LONG) h& = _OPENCLIENT("HTTP:" + url) statusCode = _STATUSCODE(h&) WHILE NOT EOF(h&) _LIMIT 60 GET #h&, , s$ content$ = content$ + s$ WEND CLOSE #h& Download$ = content$ END FUNCTION |
See also
- _OPENHOST, _OPENCONNECTION
- _CONNECTED, _CONNECTIONADDRESS$
- Email Demo, Inter-Program Data Sharing Demo
- Downloading Files