|
| 1 | +\page SOCKFLUSH SOCKFLUSH Keyword |
| 2 | + |
| 3 | +```basic |
| 4 | +SOCKFLUSH integer-variable |
| 5 | +``` |
| 6 | + |
| 7 | +Blocks until any **pending outbound data** for the given TCP socket has been **flushed from the BASIC send buffer** to the TCP stack. |
| 8 | +Use after \ref SOCKWRITE "SOCKWRITE" when you need to ensure queued bytes have been handed off before proceeding (e.g. before closing the socket). |
| 9 | + |
| 10 | +@note This waits for the **local send buffer to empty**; it does **not** wait for peer acknowledgements. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +### How to use it |
| 15 | + |
| 16 | +* `integer-variable` must contain a socket handle returned by \ref CONNECT "CONNECT" or \ref SOCKACCEPT "SOCKACCEPT". |
| 17 | +* The statement **yields** like \ref SOCKREAD "SOCKREAD": your program pauses and resumes automatically when the condition is met. |
| 18 | +* Typical use is `SOCKWRITE` → `SOCKFLUSH` → `SOCKCLOSE`. |
| 19 | + |
| 20 | +@note Press `CTRL+ESC` at any time to **cancel** waiting. |
| 21 | +@note Without an error handler, the program **terminates** on errors; with `ON ERROR`, control passes to your handler. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +### Examples |
| 26 | + |
| 27 | +**Send a line, flush, then close** |
| 28 | + |
| 29 | +```basic |
| 30 | +server = SOCKLISTEN(NETINFO$("ip"), 2000, 5) |
| 31 | +client = SOCKACCEPT(server) |
| 32 | +IF client >= 0 THEN |
| 33 | + SOCKWRITE client, "HELLORLD!" + CHR$(13) + CHR$(10) |
| 34 | + SOCKFLUSH client |
| 35 | + SOCKCLOSE client |
| 36 | +END IF |
| 37 | +SOCKCLOSE server |
| 38 | +``` |
| 39 | + |
| 40 | +**Ensure data is flushed before reusing variables** |
| 41 | + |
| 42 | +```basic |
| 43 | +CONNECT s, "93.184.216.34", 80 |
| 44 | +SOCKWRITE s, "HEAD / HTTP/1.0" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10) |
| 45 | +SOCKFLUSH s |
| 46 | +SOCKCLOSE s |
| 47 | +``` |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +### Notes |
| 52 | + |
| 53 | +* If the socket has no pending data, `SOCKFLUSH` returns immediately. |
| 54 | +* If the connection is no longer valid (e.g. already closed), `SOCKFLUSH` returns without waiting. |
| 55 | +* Use \ref SOCKSTATUS "SOCKSTATUS" to query whether a socket is connected. |
| 56 | + |
| 57 | +**See also:** |
| 58 | +\ref SOCKWRITE "SOCKWRITE" · |
| 59 | +\ref SOCKREAD "SOCKREAD" · |
| 60 | +\ref SOCKCLOSE "SOCKCLOSE" · |
| 61 | +\ref CONNECT "CONNECT" · |
| 62 | +\ref SOCKACCEPT "SOCKACCEPT" · |
| 63 | +\ref SOCKLISTEN "SOCKLISTEN" |
0 commit comments