Writing a simple TestClient with the Visual Basic SDK

Top  Previous  Next
Create a new project of type Standard EXE. Change the caption of Form1 to 'My TCP client' or something you prefer.
Add an SDK control to your form. If you can't see the control on the toolbar, use Project Components, tick Whisker SDK ActiveX Control Module and click OK. See illustration below:

 

VBAddingSDKControl

 

This will add the control to the toolbar so you can use it. Change the name of the SDK Control control (in the properties box) from 'SDKControl1' to 'Mytask' (or something).
Add three TextBox controls to the form. Name them txtSend, txtInfo and txtEvent.
Add a CommandButton control and name it cmdConnect. Change its caption to 'Connect'.
Add another CommandButton called cmdSend, with the caption 'Send'.
Choose View Code to see the form's code. Add the following code to the form (just paste it in; you don't have to type the comments, which are lines beginning with an apostrophe):

 

Private Sub cmdConnect_Click()

       MyTask.ConnectToServer

End Sub

 

Private Sub cmdSend_Click()

       MyTask.SendToServer txtSend.Text

       ' When you click the "Send" command button, this sends

       ' the contents of the "txtSend" text box to WhiskerServer

End Sub

 

Private Sub Mytask_Info(ByVal InfoMessage As String, ByVal Time As Long)

       txtInfo.Text = InfoMessage

End Sub

 

Private Sub Mytask_Event(ByVal EventMessage As String, ByVal Time As Long)

       txtEvent.Text = EventMessage

End Sub

 

You can change the IP name/address and port number of your WhiskerServer in the properties page of the SDK control. Use 'loopback' if the server is running on the same machine as the client. Port 3233 is the default. You can change these settings when the program is running (but before the client is connected) by using the .ChangeSettings command. Try putting a command button on to do this (there's an example in the FR ratio project).
Save the project.
Start the server and run the project (click the Do-it button). You should be able to connect, see messages coming from the server, and issue commands.
When you want to compile your project to an executable (.EXE) file, choose File Make Project1.exe (this may show a different name if you have renamed the project). Choose a filename and click OK.

 

Technical note: executable

TechNote_MagnifyingGlass

The resultant executable file will run directly on any computer with the SDK installed. Note that whenever you use a control from a .OCX or .DLL file in an EXE, that control must be installed (registered) on the machine you wish to run the program on. See the VB documentation for details about this. The SDK Setup program will register the control for you.

 

You might like to experiment with changing the txtOutput text box to a list box, so you can see several recent messages from the server. But that's just cosmetic.