Page 1
Page 2
Page 3
The Client
The client form is set out thus:-

We connect to the server on port 9875
(client connection has been fully covered in previous articles).
After connecting, we enable the 'Open' button. To
open our database, we do the following:-
Private Sub cmdOpen_Click()
Sbuff = "OPENProvider=Microsoft.Jet."
Sbuff = Sbuff & "OLEDB.4.0;Data Source="
Sbuff = Sbuff & txtDb.Text & "~"
Trec = 0
tcpClient.SendData Sbuff
End Sub
We set the first 4 bytes to the function
(OPEN) and then append to it the connection string.
Any ADO connection string should be valid. We terminate
the string with '~', and send it to the server. When
the 'dataarrival' event fires,
we do the same as on the server, i.e. collect all the data
until we get a termination character.
Private Sub tcpClient_DataArrival _
(ByVal bytesTotal As Long)
If Trec = 0 Then
Rbuff = ""
End If
tcpClient.GetData WkBuff
Trec = Trec + bytesTotal
Rbuff = Rbuff & WkBuff
If InStr(WkBuff, "~") <> 0 Then 'End of
data
Trec = 0
Rbuff = Mid(Rbuff, 1, Len(Rbuff) - 1)
Process_The_Data
End If
End Sub
Again, we have a Process_The_Data
sub, to deal with the data we get back from the server.
Private Sub Process_The_Data()
Dim Obuff As String
Dim WkErr
Obuff = Mid(Rbuff, 7, Len(Rbuff) - 6)
WkBuff = Mid(Rbuff, 1, 6)
Select Case WkBuff
Case "OPENOK"
cmdOpen.Enabled = False
cmdretrieve.Enabled = True
cmdClose.Enabled = True
Case "OPENER"
WkErr = Split(Obuff, ",")
Err.Raise WkErr(0), , WkErr(1)
Case "READOK"
Process_Records
Case "READER"
WkErr = Split(Obuff, ",")
Err.Raise CLng(WkErr(0)), , WkErr(1)
End Select
End Sub
Our function return is 6 characters,
so we split off the buffer accordingly. If we get an error,
the server is returning us the error number, and the error
message, so we can raise an error. We get the number and
message by using the split function, and putting them in
the variable WkErr. Providing our database opens
ok, we enable the Retrieve and Close buttons.
Previous Page
Next Page