Modifying the Pocket PC Application
Back in the Pocket PC (GPSTracking) project, add a new Class item to the project and name it as Sync.vb. Populate the class with the following:
Imports System.Net
Imports System.Net.Sockets
Public Class Sync
Const portNo As Integer = 3456
Dim client As Socket
Public Sub PerformSync( _
ByVal HostIP As String, _
ByVal txtData As String)
Try
Dim RemoteAdd As System.Net.IPAddress = _
System.Net.IPAddress.Parse(HostIP)
Dim endPoint As New IPEndPoint(RemoteAdd, portNo)
client = New Socket(endPoint.AddressFamily, _
SocketType.Stream, ProtocolType.Tcp)
client.Connect(endPoint)
'---send a message to the server
Dim data As Byte() = _
System.Text.Encoding.ASCII.GetBytes(txtData)
'---send the text---
client.Send(data)
client.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
The purpose of this class is to open a socket connection to the server and send the ID of the user, as well as latitude and longitude information, to it.
In Form1.vb, declare and instantiate the Sync class so that you can connect to the server:
 | |
Figure 9. Testing the entire system and tracking two different users. |
Public Class Form1
'---use for synchronization---
Dim sync As New Sync
Modify the
processGPSData() subroutine so that after displaying the latitude and longitude information on the screen, you will send the data to the server:
Private Sub processGPSData(ByVal str As String)
Dim rawLatLng As Double
Try
...
...
'---display the lat and lng---
lblLat.Text = "Lat:" & lat
lblLng.Text = "Lng:" & lng
'---synchronize with the server---
sync.PerformSync(ServerIP, ID & ":" & lat & ":" &
...
...
End Sub
That's it! You can now test the entire system. With the server running, run the Pocket PC application and click the Connect GPS menu item. By default, the ID of the Pocket PC application is set to "1", and hence the left map on the server (see
Figure 9) will display the location for user "1". If you set the ID of the Pocket PC application to "2", the right map will be updated instead. Hence, the system in this article allows two Pocket PCs to be traced at the same time (of course, you can scale it up to monitor multiple users).