home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / auto / cm95-10.zip / IFINGER.WIL < prev    next >
Text File  |  1996-08-30  |  2KB  |  75 lines

  1. ;******** Sample Winsock app using non-blocking socket ********
  2. szTitle = "ClockMan Finger pgm"
  3.  
  4. ;Dial our host...
  5. hConn = SDialUp ("%param1%")
  6. if (!hConn)
  7.     nRet = SGetLastErr ()
  8.     Message (szTitle, "SDialUp error = %nRet%")
  9.     exit
  10. endif
  11.  
  12. szHost = "x"
  13. szCmd = "x"
  14. while (szHost<>"" && szCmd<>"")
  15.     ; Get a finger request...
  16.     szHost = AskLine (szTitle, "Enter the host to query:", "")
  17.     if (szHost=="")
  18.         goto HangUp
  19.     endif
  20.     szCmd = AskLine (szTitle, "Enter the finger request:", "")
  21.     if (szCmd=="")
  22.         goto HangUp
  23.     endif
  24.     szCmd = StrCat (szCmd, @CRLF)
  25.  
  26.     ; Create a socket...
  27.     hSock = SOpen (@SNonBlocking)
  28.     if (hSock==@SErrSocket)
  29.         Message (szTitle, "Couldn't create socket.")
  30.         goto HangUp
  31.     endif
  32.  
  33.     ; Connect it up...
  34.     nRet = SConnect (hSock, szHost, "finger")
  35.     if (nRet <> @TRUE)
  36.         nErr = SGetLastErr ()
  37.         Message (szTitle, "SConnect error: %nErr%")
  38.         goto CloseSocket
  39.     endif
  40.  
  41.     ; Send our Finger request...
  42.     nRet = SSendLine (hSock, szCmd)
  43.     while (nRet==@SErrMustWait)
  44.         nRet = SSendLine (hSock, szCmd)
  45.     endwhile
  46.     if (nRet<>@SOK)
  47.         Message(szTitle, "Error %nRet% sending command.")
  48.         goto CloseSocket
  49.     endif
  50.  
  51.     ; Get all lines from Finger server till it closes the connection...
  52.     szResponse = ""
  53.     szLine = SRecvLine (hSock, 32767)
  54.     nRet = SGetLastErr()
  55.     while (nRet<>@SErrNoConn)
  56.         if (nRet == @SOK)
  57.             szResponse = StrCat (szResponse, szLine, @CRLF)
  58.         endif
  59.         Yield ()        
  60.         szLine = SRecvLine (hSock, 32767)
  61.         nRet = SGetLastErr()
  62.     endwhile
  63.  
  64.     Message (szTitle, szResponse)
  65.  
  66.     ; Close the socket...
  67.     :CloseSocket
  68.     nRet = SClose (hSock)
  69. endwhile
  70.  
  71. ; Hang up...
  72. :Cancel
  73. :HangUp
  74. nRet = SHangUp (hConn)
  75.