Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

Sockets project with eVB and VB6.

Written by Pete Vickers  [author's bio]  [read 82930 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3 

This design will allow us to pass data between the client and the server.

We will now put some code behind some of the controls.

Private Sub Form_Load()
Dim hostname As String
hostname = Space(30)
iret = Cegethostname(hostname)
lblClient = "This client is: " & hostname
End Sub

This will display the name of the pocket pc in the label, when the project is loaded.

Now the most complicated part - connecting to the server.

Private Sub cmdConnect_Click()
If Len(Trim(txtHname)) = 0 And _
Len(Trim(txtIp)) = 0 Then
MsgBox _
"Please enter a host name or host address",_
vbInformation, "Enter a host"
txtIp.SetFocus
Exit Sub
End If

' Sockets requires that we issue a
' call to WSAStartup to initialise
' the sockets. We want version 1.1
' but Pocket PC doesn't care!
' You can use the debug flag to get
' the dll to display progress messages
'
ivreq = &H101
iret = CeWSAStartup(ivreq, CInt(ckDEbug.Value))

If iret <> 0 Then
MsgBox _
"Error returned from CeWSAStartup - " _
& iret, vbCritical, "CeWSAStartup"
Exit Sub
End If

' Next we need to create a socket
' to enable us to talk to the host
'
isocket = CeSocket()

If isocket < 0 Then
MsgBox
"Error returned from CeSocket - " _
& iret, vbCritical, "CeSocket"
Exit Sub
End If

' Now connect to the socket we have created
' We are using port 9876 for testing.
' There is a list of known ports in the
' file c:\winnt\system32\drivers\etc\services
' e.g Telnet uses port 23, ftp 21
' We DON'T want to use a known port
'
Dim Shost As String
If Len(Trim(txtHname)) <> 0 Then
Shost = txtHname
End If
If Len(Trim(txtIp)) <> 0 Then
Shost = txtIp
End If

iret = CeConnect(isocket, 9876, Shost)

If iret <> 0 Then
MsgBox _
"Error returned from CeConnect - " _
& iret, vbCritical, "CeConnect"
Exit Sub
End If

'
' If we have reached here, we have a connection to our server
'
MsgBox _
"Successful connection - Now enter some " & _
"data in the 'Send' box, and click on 'Send'" _
, vbInformation, "Send Data"
'
' Tidy up a little bit
'
cmdSend.Enabled = True
cmdRecv.Enabled = True
cmdReset.Enabled = True
cmdConnect.Enabled = False

End Sub

Phew!! - All done. Admittedly not as easy as 'winsock1.connect', but as you read on, I'm sure you will find it is worth the effort.

Previous Page  Next Page