1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-03 14:41:21 +00:00
QB64-PE/internal/help/_OPENCONNECTION.txt

51 lines
2.2 KiB
Plaintext
Raw Normal View History

2016-03-18 11:36:04 +00:00
{{DISPLAYTITLE:_OPENCONNECTION}}
2017-10-10 14:55:21 +00:00
The [[_OPENCONNECTION]] function opens a connection from a client that the host has detected and returns a status handle.
{{PageSyntax}}
2017-10-10 14:55:21 +00:00
:{{Parameter|connectHandle}} = [[_OPENCONNECTION]]({{Parameter|hostHandle}})
{{PageDescription}}
2017-10-10 14:55:21 +00:00
* Valid {{Parameter|connectHandle}} values returned are negative numbers.
* If the syntax is correct but they fail to begin/connect, a {{Parameter|connectHandle}} of 0 is returned.
* Always check if the handle returned is 0 (failed) before continuing.
2017-10-10 14:55:21 +00:00
* [[CLOSE]] #{{Parameter|connectHandle}} closes the connection. Failed connections({{Parameter|connectHandle}} = 0) do not need to be closed.
* As a '''Host''' you can check for new clients (users). Each will have a unique connection handle.
* Creates an [[ERROR Codes|Illegal Function Call]] error if called with a string argument of the wrong syntax.
* Handle values can be used as the open number by [[INPUT (TCP/IP statement)|INPUT #]] or [[GET (TCP/IP statement)|GET #]] read statements and [[PUT (TCP/IP statement)|PUT #]] or [[PRINT (TCP/IP statement)|PRINT #]] write statements.
{{PageExamples}}
2017-10-10 14:55:21 +00:00
''Example:'' Using the [[_OPENCONNECTION]] new client return with [[INPUT (TCP/IP statement)|INPUT]] # or [[GET (TCP/IP statement)|GET]] # message or data reads.
{{CodeStart}}
2019-04-15 01:15:33 +00:00
host = {{Cl|_OPENHOST}}("TCP/IP:8080")
{{Cl|DO}}
newclient = {{Cl|_OPENCONNECTION}}(host) ' monitor host connection
{{Cl|IF...THEN|IF}} newclient {{Cl|THEN}}
{{Cl|SLEEP}} 1 ' wait one second for data to arrive
{{Cl|INPUT (TCP/IP statement)|INPUT}} #newclient, a
{{Cl|PRINT}} a
{{Cl|CLOSE}} #newclient ' close after each read
{{Cl|ELSE}} : {{Cl|_DELAY}} .05 ' share resources with other programs (20 loops per second)
{{Cl|END IF}}
2019-04-15 01:15:33 +00:00
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> "" ' any keypress quits
{{Cl|CLOSE}} #host
{{Cl|SYSTEM}}
{{CodeEnd}}
''Explanation:'' The function finds new clients and waits one second to read a message or other data. If a message or data was sent, it displays it on the screen and closes the connection.
'''Note: When sending data, the client should wait about 3 seconds before closing their connection!'''
{{PageSeeAlso}}
2016-03-18 11:36:04 +00:00
* [[_OPENHOST]], [[_OPENCLIENT]]
* [[_CONNECTED]], [[_CONNECTIONADDRESS]]
2019-04-15 01:15:33 +00:00
{{PageNavigation}}