Return to the PC Tips
VB Socket Code
Here's some code to work with the VB6 WinSock.OCX
Option Explicit Dim sBuffer() As String Private Function PostWS_Data(ByVal Index As Long) As Boolean Dim lLength As Long Dim nFile As Integer lLength = 0 PostWS_Data = False With Connections(Index) Select Case .BlockType Case blkSingleRead lLength = Len(sBuffer(Index)) Case blk2ByteHeader If Len(sBuffer(Index)) >= 2 Then lLength = cnvStringToLong(Left$(sBuffer(Index), 2)) If Len(sBuffer(Index)) >= (lLength + 2) Then sBuffer(Index) = Mid$(sBuffer(Index), 3) Else lLength = 0 End If End If Case blk4ByteHeader If Len(sBuffer(Index)) >= 4 Then lLength = cnvStringToLong(Left$(sBuffer(Index), 4)) If Len(sBuffer(Index)) >= (lLength + 4) Then sBuffer(Index) = Mid$(sBuffer(Index), 5) Else lLength = 0 End If End If Case blkFillBuffer If Len(sBuffer(Index)) >= .BufferSize Then lLength = .BufferSize Case blkDelimiter lLength = InStr(1, sBuffer(Index), .Delimiter) End Select If lLength Then If .RecordCount > UBound(.Text) Then ReDim Preserve .Text (.RecordCount) .Text(.RecordCount) = Left$(sBuffer(Index), lLength) .RecordCount = .RecordCount + 1 If bLogToFile Then nFile = FreeFile Open "C:\T3Client.Log" For Append As #nFile Print #nFile, .RecordCount & "RECV:" & vbCrLf & Left $(sBuffer(Index), lLength) Close #nFile End If sBuffer(Index) = Mid$(sBuffer(Index), lLength + 1) PostWS_Data = True End If End With End Function Private Sub Form_Initialize() ReDim sBuffer(0) End Sub Private Sub Form_Terminate() ReDim sBuffer(0) End Sub Private Sub WS_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim sTmp As String Connections(Index).ErrorNumber = 0 Connections(Index).ErrorDescription = "" If bytesTotal Then sTmp = Space$(bytesTotal) WS(Index).GetData sTmp If Index > UBound(sBuffer) Then ReDim Preserve sBuffer(Index) sBuffer(Index) = sBuffer(Index) & sTmp Do While PostWS_Data(Index): Loop End If End Sub Private Sub WS_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) Connections(Index).ErrorNumber = Number Connections(Index).ErrorDescription = Description End Sub Ken Slaugh (707) 795-1512 x118 Chouinard & Myhre, Inc. AS/400 Professional Administrator/MSE Client Access Specialist http://www.cm-inc.com/
[report a broken link by clicking here]