Click here to Skip to main content
15,897,371 members
Articles / High Performance Computing / Parallel Processing

Use of free SocketPro package for creating super client and server applications

Rate me:
Please Sign up or sign in to vote.
4.48/5 (19 votes)
23 Feb 200211 min read 181.4K   6.3K   59  
A set of socket libraries for writing distributed computing applications over the internet
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
Begin VB.Form frmDNSResolver 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "DNS Resolving with high speed"
   ClientHeight    =   5535
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7140
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5535
   ScaleWidth      =   7140
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdClear 
      Caption         =   "Clear msg"
      Height          =   375
      Left            =   5400
      TabIndex        =   22
      Top             =   4920
      Width           =   1455
   End
   Begin VB.CommandButton cmdParallel 
      Caption         =   "All running in parallel"
      Height          =   375
      Left            =   3360
      TabIndex        =   21
      Top             =   4920
      Width           =   1935
   End
   Begin VB.CommandButton cmdBatch2 
      Caption         =   "Batch calls 2"
      Enabled         =   0   'False
      Height          =   375
      Left            =   1680
      TabIndex        =   20
      Top             =   4920
      Width           =   1575
   End
   Begin VB.CommandButton cmdBatch 
      Caption         =   "Batch calls 1"
      Enabled         =   0   'False
      Height          =   375
      Left            =   120
      TabIndex        =   19
      Top             =   4920
      Width           =   1515
   End
   Begin RichTextLib.RichTextBox txtHostEnt 
      Height          =   2235
      Left            =   120
      TabIndex        =   18
      Top             =   2580
      Width           =   6795
      _ExtentX        =   11986
      _ExtentY        =   3942
      _Version        =   393217
      Enabled         =   -1  'True
      ScrollBars      =   3
      TextRTF         =   $"frmDNSResolver.frx":0000
   End
   Begin VB.TextBox txtIPAddr 
      Height          =   375
      Left            =   1500
      TabIndex        =   17
      Top             =   2160
      Width           =   3795
   End
   Begin VB.TextBox txtName 
      Height          =   375
      Left            =   1500
      TabIndex        =   15
      Top             =   1740
      Width           =   3795
   End
   Begin VB.TextBox txtClients 
      Height          =   375
      Left            =   1500
      MultiLine       =   -1  'True
      TabIndex        =   13
      Top             =   1320
      Width           =   3795
   End
   Begin VB.TextBox txtCount 
      BeginProperty DataFormat 
         Type            =   1
         Format          =   "0"
         HaveTrueFalseNull=   0
         FirstDayOfWeek  =   0
         FirstWeekOfYear =   0
         LCID            =   1033
         SubFormatType   =   1
      EndProperty
      Height          =   375
      Left            =   1500
      TabIndex        =   10
      Top             =   900
      Width           =   3795
   End
   Begin VB.CommandButton cmdDisconnect 
      Caption         =   "Disconnect"
      Height          =   375
      Left            =   5340
      TabIndex        =   9
      Top             =   420
      Width           =   1575
   End
   Begin VB.CommandButton cmdDNSByAddr 
      Caption         =   "Get DNS by addr"
      Enabled         =   0   'False
      Height          =   375
      Left            =   5340
      TabIndex        =   8
      Top             =   2160
      Width           =   1575
   End
   Begin VB.CommandButton cmdDNSByName 
      Caption         =   "Get DNS by name"
      Enabled         =   0   'False
      Height          =   375
      Left            =   5340
      TabIndex        =   7
      Top             =   1740
      Width           =   1575
   End
   Begin VB.CommandButton cmdGetClients 
      Caption         =   "Get clients"
      Enabled         =   0   'False
      Height          =   375
      Left            =   5340
      TabIndex        =   6
      Top             =   1320
      Width           =   1575
   End
   Begin VB.CommandButton cmdGetCount 
      Caption         =   "Get count of clients"
      Enabled         =   0   'False
      Height          =   375
      Left            =   5340
      TabIndex        =   5
      Top             =   900
      Width           =   1575
   End
   Begin VB.CommandButton cmdConnect 
      Caption         =   "Connect"
      Height          =   375
      Left            =   5340
      TabIndex        =   4
      Top             =   0
      Width           =   1575
   End
   Begin VB.TextBox txtPort 
      BeginProperty DataFormat 
         Type            =   1
         Format          =   "0"
         HaveTrueFalseNull=   0
         FirstDayOfWeek  =   0
         FirstWeekOfYear =   0
         LCID            =   1033
         SubFormatType   =   1
      EndProperty
      Height          =   375
      Left            =   4380
      TabIndex        =   3
      Text            =   "1739"
      Top             =   420
      Width           =   915
   End
   Begin VB.TextBox txtHost 
      Height          =   375
      Left            =   180
      TabIndex        =   2
      Top             =   420
      Width           =   4155
   End
   Begin VB.Label lblIPAddr 
      Caption         =   "IP Addr:"
      Height          =   315
      Left            =   180
      TabIndex        =   16
      Top             =   2160
      Width           =   1035
   End
   Begin VB.Label lblName 
      Caption         =   "Name:"
      Height          =   315
      Left            =   180
      TabIndex        =   14
      Top             =   1740
      Width           =   1215
   End
   Begin VB.Label lblClients 
      Caption         =   "Clients:"
      Height          =   315
      Left            =   180
      TabIndex        =   12
      Top             =   1320
      Width           =   1035
   End
   Begin VB.Label lblCount 
      Caption         =   "Count of clients:"
      Height          =   255
      Left            =   180
      TabIndex        =   11
      Top             =   960
      Width           =   1215
   End
   Begin VB.Label lblPort 
      Caption         =   "Port:"
      Height          =   255
      Left            =   4440
      TabIndex        =   1
      Top             =   120
      Width           =   795
   End
   Begin VB.Label lblHost 
      Caption         =   "Host:"
      Height          =   255
      Left            =   180
      TabIndex        =   0
      Top             =   120
      Width           =   2595
   End
End
Attribute VB_Name = "frmDNSResolver"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim IDNSResolver As DRESOLVERLib.DNS
Dim IDNSResolver2 As DRESOLVERLib.DNS
Dim WithEvents IClientSocket As CLIENTSOCKETLib.SktClient
Attribute IClientSocket.VB_VarHelpID = -1
Dim WithEvents IClientSocket2 As CLIENTSOCKETLib.SktClient
Attribute IClientSocket2.VB_VarHelpID = -1

Private Sub cmdBatch_Click()
    'send all of calls in one stream to the server side for processing
    IDNSResolver.GetDnsByAddr txtIPAddr.Text
    IDNSResolver.GetCountClients
    IDNSResolver.GetDnsByName txtName.Text
    IDNSResolver.GetDnsByName "www.cnn.com"
    IDNSResolver.GetDnsByName "www.oracle.com"
    IDNSResolver.GetDnsByName "www.yahoo.com"
    IDNSResolver.GetClients
    IDNSResolver.GetDnsByName txtName.Text
End Sub

Private Sub cmdBatch2_Click()
    'send all of calls in one stream to the server side for processing
    IDNSResolver.GetDnsByAddr "209.18.214.241"
    IDNSResolver.GetDnsByName "www.usatoday.com"
    IDNSResolver.GetDnsByName "www.geocities.com"
End Sub

Private Sub cmdClear_Click()
    txtHostEnt.Text = ""
End Sub

Private Sub cmdConnect_Click()
    On Error GoTo cerrHandler
    IClientSocket.Connect txtHost.Text, txtPort.Text
    Exit Sub
cerrHandler:
    MsgBox "Error happens, and error code = " & IClientSocket.GetRtn
End Sub

Private Sub cmdDisconnect_Click()
    IClientSocket.ShutDown
    IClientSocket2.ShutDown
End Sub

Private Sub cmdDNSByAddr_Click()
    txtHostEnt.Text = ""
    IDNSResolver.GetDnsByAddr txtIPAddr.Text
End Sub

Private Sub cmdDNSByName_Click()
    txtHostEnt.Text = ""
    IDNSResolver.GetDnsByName txtName.Text
End Sub

Private Sub cmdGetClients_Click()
    IDNSResolver.GetClients
End Sub

Private Sub cmdGetCount_Click()
    IDNSResolver.GetCountClients
End Sub

Private Sub cmdParallel_Click()
    If cmdBatch2.Enabled Then
        Call cmdBatch2_Click
    End If
    If cmdBatch.Enabled Then
        Call cmdBatch_Click
    End If
End Sub

Private Sub Form_Load()
    Set IDNSResolver = New DRESOLVERLib.DNS
    Set IDNSResolver2 = New DRESOLVERLib.DNS
    Set IClientSocket = IDNSResolver
    Set IClientSocket2 = IDNSResolver
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set IDNSResolver = Nothing
    Set IClientSocket = Nothing
    Set IDNSResolver2 = Nothing
    Set IClientSocket2 = Nothing
End Sub

Private Sub IClientSocket_OnDataAvailable(ByVal hSocket As Long, ByVal lBytes As Long, ByVal lInfo As Long)
    Select Case lInfo
      Case DRESOLVERLib.idGetClients
         txtClients.Text = IDNSResolver.Clients
      Case DRESOLVERLib.idGetCountClients
         txtCount.Text = IDNSResolver.Count
      Case DRESOLVERLib.idGetDNSByAddr
         txtHostEnt.Text = txtHostEnt.Text + IDNSResolver.GetHostEnt
      Case DRESOLVERLib.idGetDNSByName
         txtHostEnt.Text = txtHostEnt.Text + IDNSResolver.GetHostEnt
      Case Else
         If lInfo < 0 Then
            MsgBox "Error happens, or unknown method called, and info = " & CStr(lInfo)
        End If
   End Select
End Sub

Private Sub IClientSocket_OnSocketClosed(ByVal hSocket As Long, ByVal lError As Long)
    cmdGetCount.Enabled = False
    cmdDNSByAddr.Enabled = False
    cmdDNSByName.Enabled = False
    cmdGetClients.Enabled = False
    cmdBatch.Enabled = False
End Sub

Private Sub IClientSocket_OnSocketConnected(ByVal hSocket As Long, ByVal lError As Long)
    If lError = 0 Then
        cmdGetCount.Enabled = True
        cmdDNSByAddr.Enabled = True
        cmdDNSByName.Enabled = True
        cmdGetClients.Enabled = True
        cmdBatch.Enabled = True
    End If
End Sub

Private Sub IClientSocket2_OnDataAvailable(ByVal hSocket As Long, ByVal lBytes As Long, ByVal lInfo As Long)

End Sub

Private Sub IClientSocket2_OnSocketClosed(ByVal hSocket As Long, ByVal lError As Long)
    cmdBatch2.Enabled = False
End Sub

Private Sub IClientSocket2_OnSocketConnected(ByVal hSocket As Long, ByVal lError As Long)
    If lError = 0 Then
        cmdBatch2.Enabled = True
    End If
End Sub

Private Sub txtHostEnt_Change()

End Sub

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
Yuancai (Charlie) Ye, an experienced C/C++ software engineer, lives in Atlanta, Georgia. He is an expert at continuous inline request/result batching, real-time stream processing, asynchronous data transferring and parallel computation for the best communication throughput and latency. He has been working at SocketPro (https://github.com/udaparts/socketpro) for more than fifteen years.

Comments and Discussions