(c) BigSpeed Computing Inc. - Secure private networking
'Visual Basic .NET sample of secure peer-to-peer hub
'To keep this VB.NET example simple, we are going to support
'only the default user account (Guest)
Option Strict Off
Option Explicit On
Friend Class CFoMain
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Public WithEvents txtLog As System.Windows.Forms.TextBox
Public WithEvents btnClear As System.Windows.Forms.Button
Public WithEvents Frame3 As System.Windows.Forms.GroupBox
Public WithEvents btnExit As System.Windows.Forms.Button
Public WithEvents btnSettings As System.Windows.Forms.Button
Public WithEvents btnStop As System.Windows.Forms.Button
Public WithEvents btnStart As System.Windows.Forms.Button
Public WithEvents Frame2 As System.Windows.Forms.GroupBox
Public WithEvents helper As System.Windows.Forms.Button
Public WithEvents btnRemove As System.Windows.Forms.Button
Public WithEvents Frame1 As System.Windows.Forms.GroupBox
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Public WithEvents btnIP As System.Windows.Forms.Button
Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
Friend WithEvents StatusBarPanel1 As System.Windows.Forms.StatusBarPanel
Friend WithEvents StatusBarPanel4 As System.Windows.Forms.StatusBarPanel
Friend WithEvents lvPeers As System.Windows.Forms.ListView
Friend WithEvents StatusBar As System.Windows.Forms.StatusBar
Friend WithEvents P2pHub As AxbsP2pHub.AxBSP2pHubX
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(CFoMain))
Me.Frame3 = New System.Windows.Forms.GroupBox
Me.txtLog = New System.Windows.Forms.TextBox
Me.btnClear = New System.Windows.Forms.Button
Me.Frame2 = New System.Windows.Forms.GroupBox
Me.btnIP = New System.Windows.Forms.Button
Me.btnExit = New System.Windows.Forms.Button
Me.btnSettings = New System.Windows.Forms.Button
Me.btnStop = New System.Windows.Forms.Button
Me.btnStart = New System.Windows.Forms.Button
Me.helper = New System.Windows.Forms.Button
Me.Frame1 = New System.Windows.Forms.GroupBox
Me.lvPeers = New System.Windows.Forms.ListView
Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader5 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
Me.btnRemove = New System.Windows.Forms.Button
Me.StatusBar = New System.Windows.Forms.StatusBar
Me.StatusBarPanel1 = New System.Windows.Forms.StatusBarPanel
Me.StatusBarPanel4 = New System.Windows.Forms.StatusBarPanel
Me.P2pHub = New AxbsP2pHub.AxBSP2pHubX
Me.Frame3.SuspendLayout()
Me.Frame2.SuspendLayout()
Me.Frame1.SuspendLayout()
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StatusBarPanel4, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.P2pHub, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Frame3
'
Me.Frame3.BackColor = System.Drawing.SystemColors.Control
Me.Frame3.Controls.Add(Me.P2pHub)
Me.Frame3.Controls.Add(Me.txtLog)
Me.Frame3.Controls.Add(Me.btnClear)
Me.Frame3.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame3.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame3.Location = New System.Drawing.Point(11, 248)
Me.Frame3.Name = "Frame3"
Me.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame3.Size = New System.Drawing.Size(642, 182)
Me.Frame3.TabIndex = 11
Me.Frame3.TabStop = False
Me.Frame3.Text = "Log"
'
'txtLog
'
Me.txtLog.AcceptsReturn = True
Me.txtLog.AutoSize = False
Me.txtLog.BackColor = System.Drawing.SystemColors.Window
Me.txtLog.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtLog.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtLog.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtLog.Location = New System.Drawing.Point(11, 21)
Me.txtLog.MaxLength = 0
Me.txtLog.Multiline = True
Me.txtLog.Name = "txtLog"
Me.txtLog.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtLog.Size = New System.Drawing.Size(620, 121)
Me.txtLog.TabIndex = 13
Me.txtLog.Text = ""
'
'btnClear
'
Me.btnClear.BackColor = System.Drawing.SystemColors.Control
Me.btnClear.Cursor = System.Windows.Forms.Cursors.Default
Me.btnClear.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnClear.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnClear.Location = New System.Drawing.Point(12, 149)
Me.btnClear.Name = "btnClear"
Me.btnClear.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnClear.Size = New System.Drawing.Size(75, 25)
Me.btnClear.TabIndex = 12
Me.btnClear.Text = "Clear"
'
'Frame2
'
Me.Frame2.BackColor = System.Drawing.SystemColors.Control
Me.Frame2.Controls.Add(Me.btnIP)
Me.Frame2.Controls.Add(Me.btnExit)
Me.Frame2.Controls.Add(Me.btnSettings)
Me.Frame2.Controls.Add(Me.btnStop)
Me.Frame2.Controls.Add(Me.btnStart)
Me.Frame2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame2.Location = New System.Drawing.Point(9, -4)
Me.Frame2.Name = "Frame2"
Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame2.Size = New System.Drawing.Size(642, 41)
Me.Frame2.TabIndex = 4
Me.Frame2.TabStop = False
'
'btnIP
'
Me.btnIP.BackColor = System.Drawing.SystemColors.Control
Me.btnIP.Cursor = System.Windows.Forms.Cursors.Default
Me.btnIP.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnIP.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnIP.Location = New System.Drawing.Point(238, 11)
Me.btnIP.Name = "btnIP"
Me.btnIP.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnIP.Size = New System.Drawing.Size(75, 25)
Me.btnIP.TabIndex = 11
Me.btnIP.Text = "My IP"
'
'btnExit
'
Me.btnExit.BackColor = System.Drawing.SystemColors.Control
Me.btnExit.Cursor = System.Windows.Forms.Cursors.Default
Me.btnExit.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnExit.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnExit.Location = New System.Drawing.Point(312, 11)
Me.btnExit.Name = "btnExit"
Me.btnExit.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnExit.Size = New System.Drawing.Size(75, 25)
Me.btnExit.TabIndex = 8
Me.btnExit.Text = "Exit"
'
'btnSettings
'
Me.btnSettings.BackColor = System.Drawing.SystemColors.Control
Me.btnSettings.Cursor = System.Windows.Forms.Cursors.Default
Me.btnSettings.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnSettings.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnSettings.Location = New System.Drawing.Point(162, 11)
Me.btnSettings.Name = "btnSettings"
Me.btnSettings.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnSettings.Size = New System.Drawing.Size(75, 25)
Me.btnSettings.TabIndex = 7
Me.btnSettings.Text = "Settings"
'
'btnStop
'
Me.btnStop.BackColor = System.Drawing.SystemColors.Control
Me.btnStop.Cursor = System.Windows.Forms.Cursors.Default
Me.btnStop.Enabled = False
Me.btnStop.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnStop.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnStop.Location = New System.Drawing.Point(88, 11)
Me.btnStop.Name = "btnStop"
Me.btnStop.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnStop.Size = New System.Drawing.Size(75, 25)
Me.btnStop.TabIndex = 6
Me.btnStop.Text = "Stop"
'
'btnStart
'
Me.btnStart.BackColor = System.Drawing.SystemColors.Control
Me.btnStart.Cursor = System.Windows.Forms.Cursors.Default
Me.btnStart.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnStart.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnStart.Location = New System.Drawing.Point(12, 11)
Me.btnStart.Name = "btnStart"
Me.btnStart.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnStart.Size = New System.Drawing.Size(75, 25)
Me.btnStart.TabIndex = 5
Me.btnStart.Text = "Start"
'
'helper
'
Me.helper.BackColor = System.Drawing.SystemColors.Control
Me.helper.Cursor = System.Windows.Forms.Cursors.Default
Me.helper.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.helper.ForeColor = System.Drawing.SystemColors.ControlText
Me.helper.Location = New System.Drawing.Point(-152, 462)
Me.helper.Name = "helper"
Me.helper.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.helper.Size = New System.Drawing.Size(98, 21)
Me.helper.TabIndex = 1
Me.helper.Text = "Command1"
'
'Frame1
'
Me.Frame1.BackColor = System.Drawing.SystemColors.Control
Me.Frame1.Controls.Add(Me.lvPeers)
Me.Frame1.Controls.Add(Me.btnRemove)
Me.Frame1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame1.Location = New System.Drawing.Point(10, 47)
Me.Frame1.Name = "Frame1"
Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame1.Size = New System.Drawing.Size(642, 187)
Me.Frame1.TabIndex = 0
Me.Frame1.TabStop = False
Me.Frame1.Text = "Peers"
'
'lvPeers
'
Me.lvPeers.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader4, Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader5, Me.ColumnHeader3})
Me.lvPeers.FullRowSelect = True
Me.lvPeers.HideSelection = False
Me.lvPeers.Location = New System.Drawing.Point(10, 19)
Me.lvPeers.MultiSelect = False
Me.lvPeers.Name = "lvPeers"
Me.lvPeers.Size = New System.Drawing.Size(621, 128)
Me.lvPeers.TabIndex = 15
Me.lvPeers.View = System.Windows.Forms.View.Details
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Name"
Me.ColumnHeader4.Width = 99
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "IP"
Me.ColumnHeader1.Width = 99
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Port"
'
'ColumnHeader5
'
Me.ColumnHeader5.Text = "Time"
Me.ColumnHeader5.Width = 99
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Status"
Me.ColumnHeader3.Width = 99
'
'btnRemove
'
Me.btnRemove.BackColor = System.Drawing.SystemColors.Control
Me.btnRemove.Cursor = System.Windows.Forms.Cursors.Default
Me.btnRemove.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnRemove.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnRemove.Location = New System.Drawing.Point(11, 154)
Me.btnRemove.Name = "btnRemove"
Me.btnRemove.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnRemove.Size = New System.Drawing.Size(75, 25)
Me.btnRemove.TabIndex = 9
Me.btnRemove.Text = "Remove"
'
'StatusBar
'
Me.StatusBar.Location = New System.Drawing.Point(0, 440)
Me.StatusBar.Name = "StatusBar"
Me.StatusBar.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel1, Me.StatusBarPanel4})
Me.StatusBar.ShowPanels = True
Me.StatusBar.Size = New System.Drawing.Size(657, 22)
Me.StatusBar.TabIndex = 24
Me.StatusBar.Text = "StatusBar1"
'
'StatusBarPanel1
'
Me.StatusBarPanel1.Text = "StatusBarPanel1"
Me.StatusBarPanel1.Width = 150
'
'StatusBarPanel4
'
Me.StatusBarPanel4.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
Me.StatusBarPanel4.Text = "StatusBarPanel4"
Me.StatusBarPanel4.Width = 491
'
'P2pHub
'
Me.P2pHub.ContainingControl = Me
Me.P2pHub.Location = New System.Drawing.Point(163, 152)
Me.P2pHub.Name = "P2pHub"
Me.P2pHub.OcxState = CType(resources.GetObject("P2pHub.OcxState"), System.Windows.Forms.AxHost.State)
Me.P2pHub.Size = New System.Drawing.Size(289, 24)
Me.P2pHub.TabIndex = 14
'
'CFoMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(657, 462)
Me.Controls.Add(Me.StatusBar)
Me.Controls.Add(Me.Frame3)
Me.Controls.Add(Me.Frame2)
Me.Controls.Add(Me.helper)
Me.Controls.Add(Me.Frame1)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ForeColor = System.Drawing.Color.FromArgb(CType(64, Byte), CType(0, Byte), CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Location = New System.Drawing.Point(4, 27)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "CFoMain"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "BigSpeed Peer-to-Peer Hub - VB.Net sample"
Me.Frame3.ResumeLayout(False)
Me.Frame2.ResumeLayout(False)
Me.Frame1.ResumeLayout(False)
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StatusBarPanel4, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.P2pHub, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
#Region "Upgrade Support "
Private Shared m_vb6FormDefInstance As CFoMain
Private Shared m_InitializingDefInstance As Boolean
Public Shared Property DefInstance() As CFoMain
Get
If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
m_InitializingDefInstance = True
m_vb6FormDefInstance = New CFoMain
m_InitializingDefInstance = False
End If
DefInstance = m_vb6FormDefInstance
End Get
Set(ByVal Value As CFoMain)
m_vb6FormDefInstance = Value
End Set
End Property
#End Region
Dim foSettings As CFoSettings
' *** General ***
Private Function GetUsername(ByVal aHandle As Integer) As String
GetUsername = P2pHub.GetPeerName(aHandle)
If GetUsername = "" Then
GetUsername = "Guest"
End If
End Function
' *** Working ***
'Initializations
Private Sub CFoMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
foSettings = New CFoSettings 'create the settings form
foSettings.foMain = Me
SetSettings()
UpdateStatus()
End Sub
'A list view item is clicked
Private Sub lvPeers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvPeers.SelectedIndexChanged
UpdateStatus()
End Sub
'Terminate the application
Private Sub btnExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnExit.Click
End
End Sub
'Update the status text
Private Sub UpdateStatus()
If P2pHub.Running Then
StatusBar.Panels.Item(0).Text = "Started"
btnStart.Enabled = False
btnStop.Enabled = True
Else
StatusBar.Panels.Item(0).Text = "Stopped"
btnStart.Enabled = True
btnStop.Enabled = False
End If
If lvPeers.Items.Count = 0 Then
StatusBar.Panels.Item(1).Text = "No active connection"
Else
StatusBar.Panels.Item(1).Text = Str(lvPeers.Items.Count) + " connection(s)"
End If
btnRemove.Enabled = lvPeers.SelectedItems.Count > 0
End Sub
'Set the component properties
Private Sub SetSettings()
P2pHub.ListeningPort = Val(foSettings.txtPort.Text)
If foSettings.radSecret.Checked Then
P2pHub.SecurityMode = 1
Else
If foSettings.radPublic.Checked Then
P2pHub.SecurityMode = 2
Else
P2pHub.SecurityMode = 0
End If
End If
P2pHub.SecretKey = foSettings.txtSecret.Text
P2pHub.PublicKey = foSettings.txtPublic.Text
P2pHub.PrivateKey = foSettings.txtPrivate.Text
P2pHub.Fingerprints = foSettings.txtFingerprints.Text
End Sub
'Add a message to the log
Private Sub LogMsg(ByVal aText As String)
Dim Line As String
If txtLog.Text > "" Then
Line = Chr(13) & Chr(10)
End If
Line = Line & "[" & Now.ToLongTimeString & "] : "
Line = Line & aText
txtLog.SelectionStart = Len(txtLog.Text)
txtLog.SelectedText = Line
End Sub
Private Function ItemFromHandle(ByVal aHandle As Long) As ListViewItem
'iterate on the list
Dim i As Integer
For i = 0 To lvPeers.Items.Count - 1
If lvPeers.Items(i).Tag = aHandle Then
ItemFromHandle = lvPeers.Items(i)
Exit Function
End If
Next i
ItemFromHandle = Nothing
End Function
'Clear the log
Private Sub btnClear_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnClear.Click
txtLog.Text = ""
End Sub
'Remove a peer connection
Private Sub btnRemove_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnRemove.Click
If lvPeers.SelectedItems.Count = 0 Then Exit Sub
P2pHub.RemovePeer(lvPeers.SelectedItems(0).Tag)
UpdateStatus()
End Sub
'Modify the settings
Private Sub btnSettings_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnSettings.Click
If foSettings.ShowDialog <> DialogResult.OK Then Exit Sub
SetSettings()
UpdateStatus()
End Sub
'Start the hub
Private Sub btnStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnStart.Click
If P2pHub.Start Then
LogMsg(("Hub is started"))
Else
Call MsgBox("Cannot start the hub!", "Error")
End If
UpdateStatus()
End Sub
'Stop the hub
Private Sub btnStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnStop.Click
Dim i As Integer
P2pHub.Stop()
For i = lvPeers.Items.Count - 1 To 0 Step -1
P2pHub.RemovePeer(lvPeers.Items(i).Tag)
Next i
UpdateStatus()
LogMsg("Hub stopped")
End Sub
'Show my IP address
Private Sub btnIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIP.Click
MsgBox(P2pHub.LocalIPList, , "My IP address")
End Sub
' *** P2pHub events ***
'A request for a password
Private Sub P2pHub_OnNeedPassword(ByVal sender As Object, ByVal e As AxbsP2pHub.IBSP2pHubXEvents_OnNeedPasswordEvent) Handles P2pHub.OnNeedPassword
Dim aOkay As Object
If e.aUsername = "" Then
'this is a Guest user
aOkay = True
Else
'Unknown user, we accept only guests
aOkay = False
End If
End Sub
'A new peer is just connected
Private Sub P2pHub_OnPeerConnected(ByVal sender As Object, ByVal e As AxbsP2pHub.IBSP2pHubXEvents_OnPeerConnectedEvent) Handles P2pHub.OnPeerConnected
Dim LI As ListViewItem
LI = lvPeers.Items.Add("Not signed in")
LI.Tag = e.aHandle
LI.SubItems.Add(P2pHub.GetPeerAddress(e.aHandle))
LI.SubItems.Add(Str(P2pHub.GetPeerPort(e.aHandle)))
LI.SubItems.Add(Now.ToLongTimeString)
LI.SubItems.Add("Connected")
UpdateStatus()
LogMsg(("New peer at " + LI.SubItems(1).Text + ":" + LI.SubItems(2).Text))
End Sub
'A connection is broken
Private Sub P2pHub_OnPeerDisconnected(ByVal sender As Object, ByVal e As AxbsP2pHub.IBSP2pHubXEvents_OnPeerDisconnectedEvent) Handles P2pHub.OnPeerDisconnected
Dim LI As ListViewItem
LI = ItemFromHandle(e.aHandle)
If LI Is Nothing Then Exit Sub
LogMsg(("Disconnected " & LI.Text & " " & P2pHub.GetPeerAddress(e.aHandle) & ":" & Str(P2pHub.GetPeerPort(e.aHandle))))
lvPeers.Items.Remove(LI)
End Sub
'A connection is refused
Private Sub P2pHub_OnPeerRejected(ByVal sender As Object, ByVal e As AxbsP2pHub.IBSP2pHubXEvents_OnPeerRejectedEvent) Handles P2pHub.OnPeerRejected
LogMsg(("Rejected peer from " & P2pHub.GetPeerAddress(e.aHandle) & ":" & Str(P2pHub.GetPeerPort(e.aHandle))))
End Sub
End Class
(c) BigSpeed Computing Inc. - Secure private networking