Skip to content

Commit 515e1c5

Browse files
committed
- Add ToString method for Nut_Parameters
- Modified Socket parameters, hoping this will help with IPv6 support
1 parent 3b84ffa commit 515e1c5

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

WinNUT_V2/WinNUT-Client_Common/Common_Classes.vb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,14 @@ Public Class Nut_Parameter
5151
Public Password As String = ""
5252
Public UPSName As String = ""
5353
Public AutoReconnect As Boolean = False
54+
55+
''' <summary>
56+
''' Generate an informative String representing this Parameter object. Note password is not printed.
57+
''' </summary>
58+
''' <returns></returns>
59+
Public Overrides Function ToString() As String
60+
Return String.Format("{0}@{1}:{2}, Name: {3}" & If(AutoReconnect, " [AutoReconnect]", Nothing),
61+
Login, Host, Port, AutoReconnect)
62+
' Return MyBase.ToString())
63+
End Function
5464
End Class

WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ Public Class Nut_Socket
9191
Public Function Connect() As Boolean
9292
Try
9393
'TODO: Use LIST UPS protocol command to get valid UPSs.
94-
Dim Host = Me.Nut_Config.Host
95-
Dim Port = Me.Nut_Config.Port
96-
Dim Login = Me.Nut_Config.Login
97-
Dim Password = Me.Nut_Config.Password
94+
Dim Host = Nut_Config.Host
95+
Dim Port = Nut_Config.Port
96+
Dim Login = Nut_Config.Login
97+
Dim Password = Nut_Config.Password
9898

9999
If Not String.IsNullOrEmpty(Host) And Not IsNothing(Port) Then
100100
If Not Create_Socket(Host, Port) Then
@@ -133,12 +133,13 @@ Public Class Nut_Socket
133133

134134
Private Function Create_Socket(ByVal Host As String, ByVal Port As Integer) As Boolean
135135
Try
136-
Me.NutSocket = New Socket(AddressFamily.InterNetwork, ProtocolType.IP)
137-
Me.NutTCP = New TcpClient(Host, Port)
138-
Me.NutStream = NutTCP.GetStream
139-
Me.ReaderStream = New StreamReader(NutStream)
140-
Me.WriterStream = New StreamWriter(NutStream)
141-
Me.ConnectionStatus = True
136+
' NutSocket = New Socket(AddressFamily.InterNetwork, ProtocolType.IP)
137+
NutSocket = New Socket(SocketType.Stream, ProtocolType.IP)
138+
NutTCP = New TcpClient(Host, Port)
139+
NutStream = NutTCP.GetStream
140+
ReaderStream = New StreamReader(NutStream)
141+
WriterStream = New StreamWriter(NutStream)
142+
ConnectionStatus = True
142143
Catch Excep As Exception
143144
RaiseEvent OnNUTException(New Nut_Exception(Nut_Exception_Value.CONNECT_ERROR, Excep.Message), LogLvl.LOG_ERROR, Me)
144145
Me.ConnectionStatus = False

0 commit comments

Comments
 (0)