GET (TCP/IP statement): Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "'''GET''' reads unformatted (raw) data from an open TCP/IP connection opened with _OPENCLIENT, _OPENHOST or _OPENCONNECTION. {{PageSyntax}} ''Syntax 1:'' : '''GET''' ''#handle'', , ''b$'' * Reads any available data into variable length string b$ (b$'s length is adjusted to the number of bytes read, so checking EOF is unnecessary) using the handle return value from _OPENCLIENT, _OPENHOST or _OPENCONNECTION. ''Syntax 2:'' : '''GET''' ''#handle''...")
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 3: Line 3:


{{PageSyntax}}
{{PageSyntax}}
''Syntax 1:''
; Syntax 1 (using variable strings):
: '''GET''' ''#handle'', , ''b$''
: [[GET (TCP/IP statement)|GET #]]{{Parameter|handle&}}, , {{Parameter|dat$}}
* Reads any available data into variable length string b$ (b$'s length is adjusted to the number of bytes read, so checking EOF is unnecessary) using the handle return value from [[_OPENCLIENT]], [[_OPENHOST]] or [[_OPENCONNECTION]].
* Using the {{Parameter|handle&}} return value from [[_OPENCLIENT]], [[_OPENHOST]] or [[_OPENCONNECTION]], the function reads '''any available data''' into variable length string {{Parameter|dat$}}, the string length is adjusted to the number of bytes read, so checking [[EOF]] is unnecessary.
; Syntax 2 (using fixed length variables/strings):
: [[GET (TCP/IP statement)|GET #]]{{Parameter|handle&}}, , {{Parameter|dat%}}
* Using the {{Parameter|handle&}} return value from [[_OPENCLIENT]], [[_OPENHOST]] or [[_OPENCONNECTION]], the function reads an [[INTEGER]] (in the shown syntax, due to the use of an integer ('''%''') variable). If '''2 bytes for the integer are available''', they are read into {{Parameter|dat%}}, if not then '''nothing is read''' and [[EOF]] {{Parameter|handle&}} will return -1 ({{Parameter|dat%}} its value will be undefined in the latter case).




''Syntax 2:''
== Communicating using unformatted/raw streamed data ==
: '''GET''' ''#handle'', ,''x%''
* Reads an integer. If 2 bytes are available, they are read into x%, if not then nothing is read and [[EOF]](handle) will return -1 (and ''x%'''s value will be undefined) using the handle return value from [[_OPENCLIENT]], [[_OPENHOST]] or [[_OPENCONNECTION]].
 
 
==Communicating using unformatted/raw streamed data==
* Benefit: Communicate with any TCP/IP compatible protocol (eg. FTP, HTTP, web-pages, etc).
* Benefit: Communicate with any TCP/IP compatible protocol (eg. FTP, HTTP, web-pages, etc).
* Disadvantage: Streamed data has no 'message length', as such just the program deals with a continuous number of bytes in a row. Some messages get fragmented and parts of messages can (and often do) arrive at different times, due to the very nature of the TCP/IP protocol.
* Disadvantage: Streamed data has no 'message length', as such just the program deals with a continuous number of bytes in a row. Some messages get fragmented and parts of messages can (and often do) arrive at different times, due to the very nature of the TCP/IP protocol.
Line 21: Line 19:


{{PageExamples}}
{{PageExamples}}
''Example:''
;Example: Reading data of various lengths
 
{{CodeStart}}
{{CodeStart}}
{{Cl|PUT|PUT #}}​c, , a$ ' sends data  
{{Cl|GET (TCP/IP statement)|GET}} #handle&, , dat$ 'always reads any available data into variable length string
{{Cl|GET|GET #}}​o, , b$ ' reads any available data into variable length string b$ 
{{Cl|GET (TCP/IP statement)|GET}} #handle&, , dat% 'if 2 bytes (INTEGER) are available, they are read, else nothing is read
{{Cl|GET|GET #}}​o, , x% ' if 2 bytes are available, they are read into x%
{{Cl|GET (TCP/IP statement)|GET}} #handle&, , dat& 'if 4 bytes (LONG) are available, they are read, else nothing is read
{{Cl|GET (TCP/IP statement)|GET}} #handle&, , dat&& 'if 8 bytes (_INTEGER64) are available, they are read, else nothing is read
{{CodeEnd}}
{{CodeEnd}}


''Explanation:''
=== More examples ===
* Data could be a string, variable array, user defined [[TYPE]], etc.
* [[_OPENCLIENT]]
* b$'s length is adjusted to the number of bytes read. Checking [[EOF]](o) is  unnecessary.
* [[Email Demo]]
* If 2 bytes are not available for the x% integer then nothing is read and [[EOF]](o) will return -1
 
 
 
===More examples===
* ''See the examples in [[_OPENCLIENT]] or [[Email Demo]].''
 





Latest revision as of 10:42, 19 June 2024

GET reads unformatted (raw) data from an open TCP/IP connection opened with _OPENCLIENT, _OPENHOST or _OPENCONNECTION.


Syntax

Syntax 1 (using variable strings)
GET #handle&, , dat$
  • Using the handle& return value from _OPENCLIENT, _OPENHOST or _OPENCONNECTION, the function reads any available data into variable length string dat$, the string length is adjusted to the number of bytes read, so checking EOF is unnecessary.
Syntax 2 (using fixed length variables/strings)
GET #handle&, , dat%
  • Using the handle& return value from _OPENCLIENT, _OPENHOST or _OPENCONNECTION, the function reads an INTEGER (in the shown syntax, due to the use of an integer (%) variable). If 2 bytes for the integer are available, they are read into dat%, if not then nothing is read and EOF handle& will return -1 (dat% its value will be undefined in the latter case).


Communicating using unformatted/raw streamed data

  • Benefit: Communicate with any TCP/IP compatible protocol (eg. FTP, HTTP, web-pages, etc).
  • Disadvantage: Streamed data has no 'message length', as such just the program deals with a continuous number of bytes in a row. Some messages get fragmented and parts of messages can (and often do) arrive at different times, due to the very nature of the TCP/IP protocol.
  • The position parameter (between the commas) is not used in TCP/IP connections.
  • The programmer must cater for these situations manually.


Examples

Example
Reading data of various lengths
GET #handle&, , dat$ 'always reads any available data into variable length string
GET #handle&, , dat% 'if 2 bytes (INTEGER) are available, they are read, else nothing is read
GET #handle&, , dat& 'if 4 bytes (LONG) are available, they are read, else nothing is read
GET #handle&, , dat&& 'if 8 bytes (_INTEGER64) are available, they are read, else nothing is read

More examples


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link