wwsocket::Listen

Puts a socket into server mode to listen for incoming connections on a given port. If a connection is made the socket is opened for reading and writing using the regular Send/Receive etc. methods.

This method returns .T. if a connection is made, as soon as somebody connects. If no connection occurs and the timeout is reached the method returns .F. Typically you'll run the listener in a loop or off a timer to check the port.

o.Listen(lnPort,lnTimeOut)

Return Value

.T. or .F.

Parameters

lnPort
The TCP/IP port to listen to.

lnTimeOut
Timeout in seconds. Default: 10 seconds

Example

*** Very simple HTTP listener
DO WHILE .t.
   oSock = CREATEOBJECT("wwSOcket")
   oSock.lStripNulls = .T.

   *** Exit on Enter key
   lnKey = INKEY(.01,"HM")
   IF lnKey = 13
       EXIT
   ENDIF
   

   *** Listen on Port 88 for 5 seconds
   IF !oSock.Listen(88,5)
      ? oSock.cErrorMsg  && Socket timeout
      LOOP
   ENDIF

   ? oSock.Receive()  && HTTP Headers for this example

   ? oSock.Send("Hello World with Sockets!")
   oSock = .F.  && close/clear the socket
ENDDO



Client code: oHTTP = CREATE("wwHTTP") ? oHTTP.HTTPGet("http://localhost:88/") && Hello world with sockets *** or simply browse to http://localhost:88/ with your browser

See also:

Class wwsocket

© West Wind Technologies, 1996-2024 • Updated: 11/13/01
Comment or report problem with topic