PUT (TCP/IP statement): Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:




{{Parameters}}
{{PageParameters}}
* The ''handle'' value is returned by the [[_OPENCLIENT]], [[_OPENHOST]] or [[_OPENCONNECTION]] '''QB64''' functions.
* The ''handle'' value is returned by the [[_OPENCLIENT]], [[_OPENHOST]] or [[_OPENCONNECTION]] '''QB64''' functions.
* The ''data'' can be any variable type value. Literal values are not allowed.
* The ''data'' can be any variable type value. Literal values are not allowed.
Line 17: Line 17:
<center>'''Your program MUST cater for these situations manually.'''</center>
<center>'''Your program MUST cater for these situations manually.'''</center>


{{WhiteStart}}''Example: string variable b$'s length is adjusted to the number of bytes read.''
{{FixedStart}}''Example: string variable b$'s length is adjusted to the number of bytes read.''


  {{Cb|PUT (TCP/IP statement)|PUT #}}client, , a$ 'sends data (this could be a string, variable array, user defined type, etc)
  {{Cb|PUT (TCP/IP statement)|PUT #}}client, , a$ 'sends data (this could be a string, variable array, user defined type, etc)
  {{Cb|GET (TCP/IP statement)|GET #}}openconn, , b$ 'reads any available data into variable length string b$
  {{Cb|GET (TCP/IP statement)|GET #}}openconn, , b$ 'reads any available data into variable length string b$
  {{Cb|GET (TCP/IP statement)|GET #}}openconn, , x% 'reads 2 bytes of data as an integer value.
  {{Cb|GET (TCP/IP statement)|GET #}}openconn, , x% 'reads 2 bytes of data as an integer value.
{{WhiteEnd}}
{{FixedEnd}}
: ''Explanation:''  Checking [[EOF]](o) is unnecessary. If 2 bytes are available, they are read into x%, if not then nothing is read and [[EOF]](o) will return -1
: ''Explanation:''  Checking [[EOF]](o) is unnecessary. If 2 bytes are available, they are read into x%, if not then nothing is read and [[EOF]](o) will return -1


Line 31: Line 31:




''See also:''
{{PageSeeAlso}}
* [[GET (TCP/IP statement)]], [[PUT|PUT #]]
* [[GET (TCP/IP statement)]], [[PUT|PUT #]]
* [[_OPENCLIENT]], [[_OPENHOST]], [[_OPENCONNECTION]]
* [[_OPENCLIENT]], [[_OPENHOST]], [[_OPENCONNECTION]]

Latest revision as of 00:56, 29 January 2023

The PUT # TCP/IP statement sends unformatted(raw) data to an open connection using a user's handle.


Syntax

PUT #handle, , data


Parameters


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 a continuous bunch of bytes all in a row. Some messages get fragmented and parts of messages can (and often do) arrive at different times.
  • The position parameter (between the commas) is not used in TCP/IP statements as all data is streamed consecutively.
Your program MUST cater for these situations manually.
Example: string variable b$'s length is adjusted to the number of bytes read.

 PUT #client, , a$ 'sends data (this could be a string, variable array, user defined type, etc)
 GET #openconn, , b$ 'reads any available data into variable length string b$
 GET #openconn, , x% 'reads 2 bytes of data as an integer value.
Explanation: Checking EOF(o) is unnecessary. If 2 bytes are available, they are read into x%, if not then nothing is read and EOF(o) will return -1



See the example in _OPENCLIENT


See also



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