
SmartDongle VB Client/Server Example Source Code

   This zip file contains two Microsoft VB projects, Client_Form and TCPServer.


   The TCPServer project contains all files for an example server.

      TCPServer.vb contains all functions associated with the server side program.
      TCPServer.vb uses SmartDngle.vb to communicate with the SmartDongle. No changes
      need to or should be made to SmartDongle.vb.

      In order for the TCPServer program to work properly, a valid SmartDongle must
      be connected to the server with 1 byte somewhere (example uses address 11722
      but you can change it) on the SmartDongle to represent the number of available
      seats and 4 bytes somewhere (example uses address 2808 but you can change it)
      on the SmartDongle to represent the seat counter (number of times a seat has been
      given). You will need to write these locations to the SmartDongle before it can
      be used for the first time. You can find examples on how to do this with our
      other VB examples.

      There are several variables which will need to be changed for the TCPServer
      program to run properly. All of these variables are located at the top of
      the TCPServer Main Sub.
         Required changes:
            Server IP address (separated by comas, not perios).
            Dim myAddress() As Byte = {Server, IP, Address, Here}

            Server port to listen for incoming connections.
            Const portNumber As Integer = Available Listening Port Here

            You must edit the example code keys with your unique key values, for example:
               P1 = 0xec6cc589aefd1e75;
               P2 = 0xfcec0a6a82747b3f;

         Optional changes:
            Integer address on SmartDongle where available seats value is located.
            Dim seatsAddress As UInt32 = 11722

            Integer address on SmartDongle where seats counter is located.
            Dim counterAddress As UInt32 = 2808

      After the necessary variable changes have been made, you can recompile and run
      the TCPServer program on the server. If running on a 64bit system, compile as a
      32bit project. The VB code will not yet work with 64bit. Upon starting the
      TCPServer program on the server, with a valid SmartDongle attached, you should
      get a message on the console saying:
         Success: Valid SmartDongle found
         X max seats available.
         Waiting for connection...
      The message on the console will update every time a connection is made with
      information about the connection.


   The Client_Form project contains all files for an example client side program.

      ClientForm.vb contains all functions associated with controlling the client form.
      Two variables in ClientForm.vb will need to be changed for the example to run
      with your server.
         serverIPAddress must match variable myAddress from TCPServer project
         Dim serverIPAddress As String = "Your.Server.IP.Address"

         serverListeningPort must match variable portNumber from TCPServer project
         Dim serverListeningPort As Integer = Server Listening Port

      After changing the serverIPAddress and serverListeningPort you can recompile and
      run the client form. The client will run but not be able to make a connection
      until the server has been started.

      The client form example is very simple. It has a "Get Seat", a "Return Seat"
      (initially inactive), and an "Exit" button as well as a text box to display
      messages returned from the server.

      Clicking "Get Seat" will contact the server and attempt to aquire a seat. If it
      succeeds the "Get Seat" button will become inactive and the "Return Seat" button
      will become active. Also, a message will appear in the text box letting you know
      that the connection was successful and you have a seat. If it fails, a message
      from the server will be displayed in the text box.

      Clicking "Return Seat" will contact the server and attempt to return the seat. If
      it succeeds the "Return Seat" button will become inactive and the "Get Seat"
      button will become active. Also, a message will appear in the text box letting you
      know that the connection was successful and you returned your seat.

      Clicking the "Exit" or "X" button will first check if the client has a seat and
      return that seat if it does and then exit the client form program.


