Event Socket.Ready (gb.net)

Event Ready ( )

This event raises after a connection has been established successfully.

The Status property will turn to value Net.Connected.

This example checks which ports can be opened on the localhost within a given range. If the socket can connect then the ready event will fire. If the socket cannot be opened then the Status will be set to an error code with a value less than zero. While connecting the value of the Status property will be greater than zero.

Examples

PUBLIC Connection AS NEW Socket AS "SocketClient"

PUBLIC SUB ButtonScan_Click()
  DIM portNumber AS Integer
  FOR portNumber = 1 TO 3000
    Connection.Connect("localhost", portNumber)
    ' Wait until the socket is closed
    ' or an error is found
    REPEAT
      WAIT 0.01
    UNTIL Connection.Status <= Net.Inactive
    IF Connection.Status = Net.HostNotFound THEN
      PRINT "Host not found"
      ' No point in scanning if we can not find the host
      BREAK
    END IF
  NEXT
END

PUBLIC SUB SocketClient_Ready()
  PRINT "Port " & Connection.Port & " open on " & Connection.Host
  CLOSE #Connection
END

Normally, of course, you would not close a socket during the Ready event!