Quote:
> Hey, Im wondering where I might find plain-jane winsock code in VB using
the
> winsock API. Heres what I want to do:
> I cant stand event-driven winsock. I need to write something completely
> procedurally, one command after another, irregardless of whats happening
on
> the TCP/IP pipe. VB being event driven doesnt help, but I can work with it
> *if* I can get past waiting for a Winsock_DataArrival event. I want to do
an
> old-fashioned INPUT A$, taking input from the TCP/IP connection. VC++
> diehards will send me that way, but I know the gurus here can toss some
> ideas my way.
> Im sure there is, somewhere, the plain code to access winsock in a module
or
> something.
You can always use the event model to fake a procedurally flow:
Example:
' Send server name to winsock layer
cmd = "HELO " & Server & vbCrLf
winsock_sendData cmd
If winsock_reply(cmd) <> 250 Then
winsock_CloseSession
Err.Raise ERR_SERVER_CONNECT, "SmtpPlus", "Connection to server " &
Server & " failed! "
End If
Private Sub wsTCP_DataArrival(ByVal bytesTotal As Long)
wsTCP.GetData winsock_returnMessage
End Sub
Where the method winsock_reply looks like
Private Function winsock_reply(cmdInfo As String) As Long
Dim message As String
' Initialize timeout & start timer
timeout = False
smtpTimer.Enabled = True
While winsock_returnMessage = "" And Not timeout And Not intState =
CONNECT_ERROR
Sleep 1
DoEvents
Wend
If timeout Then
winsock_CloseSession
Err.Raise ERR_TIMEOUT, "SmtpPlus", "A timeout occurred after " &
timeoutPeriod & " milliseconds while processing: " & vbCrLf & cmdInfo
ElseIf intState = CONNECT_ERROR Then
winsock_reply = -1
Exit Function
End If
' no timeout so stop timer
smtpTimer.Enabled = False
' Pick up code
winsock_reply = CLng(Left(winsock_returnMessage, 3))
If winsock_reply > 400 Then
intState = SESSION_ERROR
message = "Winsock Layer generated error: (" & winsock_reply & ") -
" & Mid(winsock_returnMessage, 5) & " while processing: " & vbCrLf & cmdInfo
winsock_CloseSession
Err.Raise ERR_WINSOCK_LAYER, "SmtpPlus", message
End If
End Function
The function waits for the data to arive in the string winsock_returnMessage
picked up by the event or when the timer fires, which means a timeout
occurred.
Quote:
> And you know, I love VB...but when the heck did Print change its meaning
> from Printing to STDOUT? Why, after nearly 7 generations of VB, do we
still
> not have a STDIN and STDOUT?
Sigh!! God only knows! :-)
It has been a 'want-to-have' for ages.
Kees