Skip to content

Commit

Permalink
added event ClientBase.Reconnecting() for detection of a dropped conn…
Browse files Browse the repository at this point in the history
…ection that is about to be restored
  • Loading branch information
Ninjastorm380 committed Jun 13, 2021
1 parent 29b5ac6 commit 930f6e0
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 13 deletions.
Binary file modified .vs/Networking/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/Networking/v16/.suo
Binary file not shown.
28 changes: 21 additions & 7 deletions NetworkLibTester/Form1.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions NetworkLibTester/Form1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
TestClient1.TestCommand()
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
TestClient1.TestAutoReconnect()
End Sub
End Class
9 changes: 8 additions & 1 deletion NetworkLibTester/TestClient.vb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
Public Class TestClient : Inherits Networking.ClientBase
Private Client As Networking.TcpClient = Nothing
Public Sub TestAutoReconnect()
Client.Close()
End Sub
Protected Friend Sub IsReconnecting() Handles Me.Reconnecting
MsgBox("lost connection, but we reconnected successfully!", MsgBoxStyle.OkOnly, "TestForm - test client")
End Sub
Public Sub TestCommand()
If Client IsNot Nothing AndAlso Client.Connected = True Then
MsgBox("sending test message...", MsgBoxStyle.OkOnly, "TestForm - test client")
Client.WriteJagged({Text.Encoding.ASCII.GetBytes("test message")})
End If
End Sub
Expand All @@ -16,7 +23,7 @@
Dim ReceivedMessage As String = Text.Encoding.ASCII.GetString(ReceivedData(0))
Select Case ReceivedMessage
Case "test response"
Debug.Print("received test message!")
MsgBox("client received test response!", MsgBoxStyle.OkOnly, "TestForm - test client")
End Select
End If
Limiter.Limit()
Expand Down
1 change: 1 addition & 0 deletions NetworkLibTester/TestServer.vb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Dim ReceivedMessage As String = Text.Encoding.ASCII.GetString(ReceivedData(0))
Select Case ReceivedMessage
Case "test message"
MsgBox("server received test message, responding...", MsgBoxStyle.OkOnly, "TestForm - test server")
Client.WriteJagged({Text.Encoding.ASCII.GetBytes("test response")})
End Select
End If
Expand Down
Binary file modified NetworkLibTester/bin/Release/NetworkLibTester.exe
Binary file not shown.
Binary file modified NetworkLibTester/bin/Release/Networking.dll
Binary file not shown.
Binary file not shown.
Binary file modified NetworkLibTester/obj/Release/NetworkLibTester.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 10 additions & 4 deletions Networking/BaseClasses.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Private Client As TcpClient
Private PurposeClosed As Boolean = False
Private Endpoint As Net.IPEndPoint
Protected Friend Event Reconnecting As EventHandler

Public Sub Connect(Endpoint As Net.IPEndPoint)
Me.Endpoint = Endpoint
PurposeClosed = False

If Client Is Nothing Then
Client = New TcpClient(Endpoint)
Dim AsyncLaunch As New Threading.Thread(AddressOf Prerun) : AsyncLaunch.Start()
Expand All @@ -25,8 +26,13 @@
Client = Nothing
End Sub
Private Sub Prerun()
PurposeClosed = False
Run(Client)
If PurposeClosed = False Then Connect(Endpoint)
If PurposeClosed = False Then
RaiseEvent Reconnecting(Me, EventArgs.Empty)
Connect(Endpoint)

End If
End Sub

Public MustOverride Sub Run(ByVal Client As TCPClient)
Expand All @@ -35,8 +41,8 @@ Public MustInherit Class ServerBase
Private Listener As Net.Sockets.TcpListener
Private OnlineBase As Boolean = False
Private HoldingTMP As TcpClient
Public Event ServerStarting As EventHandler
Public Event ServerStopping As EventHandler
Protected Friend Event ServerStarting As EventHandler
Protected Friend Event ServerStopping As EventHandler
Public ReadOnly Property Online As Boolean
Get
Return OnlineBase
Expand Down
Binary file modified Networking/bin/Release/netstandard2.0/Networking.dll
Binary file not shown.
Binary file modified Networking/obj/Release/netstandard2.0/Networking.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ C:\Users\demon4hire\source\repos\Ninjastorm380\Networking\Networking\obj\Release
C:\Users\demon4hire\source\repos\Ninjastorm380\Networking\Networking\obj\Release\netstandard2.0\Networking.AssemblyInfo.vb
C:\Users\demon4hire\source\repos\Ninjastorm380\Networking\Networking\obj\Release\netstandard2.0\Networking.vbproj.CoreCompileInputs.cache
C:\Users\demon4hire\source\repos\Ninjastorm380\Networking\Networking\obj\Release\netstandard2.0\Networking.dll
C:\Users\demon4hire\source\repos\Ninjastorm380\Networking\Networking\obj\Release\netstandard2.0\Networking.vbprojAssemblyReference.cache
Binary file not shown.

0 comments on commit 930f6e0

Please sign in to comment.