4 Home
John Bintz edited this page 2023-04-11 13:33:21 +00:00

Patterns

Detecting connectivity

Not-Roadshow/UAE

All other internet stacks need to be started up. Checking for a lack of bsdsocket.library in memory is an easy start.

Roadshow/UAE

  • Perform a DNS lookup of a known remote hostname. If that fails, your stack is likely not running.
  • Perform a single socket connection with a long-ish timeout (5 seconds is likely enough). If that fails, you're likely unconnected from the Internet.

Gotchas

Servers

Only the first block of sent data from the server is received

After you Accept a connection from a client, you need to watch the new socket for that client for updates, rather than the original server socket:

Do
  RESULT=Socket Wait Async Reading(SERVER, 500)
  
  If RESULT > 0
    _REMOTE_SOCKET=Socket Accept(SERVER)
    
    ' For all communication with this client, use this socket, not the SERVER socket
    Do
      RESULT=Socket Wait Async Reading(_REMOTE_SOCKET, 500)
      If RESULT > 0
        Print Socket Recv$(_REMOTE_SOCKET, 1024)
      End If
      Wait Vbl
    Loop
  End If
Loop