Skip to content

Commit 22fa490

Browse files
author
Joel Christner
committed
Revert to 1b7153f
1 parent 947eb96 commit 22fa490

File tree

18 files changed

+1702
-1291
lines changed

18 files changed

+1702
-1291
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,3 @@ __pycache__/
266266
# Cake - Uncomment if you are using it
267267
# tools/
268268

269-
/.editorconfig
270-
/WatsonTcp.ruleset

TestClient/Program.cs

Lines changed: 45 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
namespace TestClient
2-
{
3-
using System;
4-
using System.Text;
5-
using WatsonTcp;
1+
using System;
2+
using System.Text;
3+
using WatsonTcp;
64

7-
internal class TestClient
5+
namespace TestClient
6+
{
7+
class TestClient
88
{
9-
private static string serverIp = String.Empty;
10-
private static int serverPort = 0;
11-
private static bool useSsl = false;
12-
private static string certFile = String.Empty;
13-
private static string certPass = String.Empty;
14-
private static bool acceptInvalidCerts = true;
15-
private static bool mutualAuthentication = true;
16-
private static WatsonTcpClient client = null;
17-
private static string presharedKey = null;
18-
19-
private static void Main()
9+
static string serverIp = "";
10+
static int serverPort = 0;
11+
static bool useSsl = false;
12+
static string certFile = "";
13+
static string certPass = "";
14+
static bool acceptInvalidCerts = true;
15+
static bool mutualAuthentication = true;
16+
static WatsonTcpClient client = null;
17+
static string presharedKey = null;
18+
19+
static void Main(string[] args)
2020
{
2121
serverIp = Common.InputString("Server IP:", "127.0.0.1", false);
2222
serverPort = Common.InputInteger("Server port:", 9000, true, false);
@@ -105,32 +105,21 @@ private static void Main()
105105
}
106106
else
107107
{
108-
client = new WatsonTcpClient(serverIp, serverPort)
109-
{
110-
ServerConnected = ServerConnected,
111-
ServerDisconnected = ServerDisconnected,
112-
MessageReceived = MessageReceived,
113-
};
114-
115-
client.Start();
108+
client = new WatsonTcpClient(serverIp, serverPort);
109+
client.ServerConnected = ServerConnected;
110+
client.ServerDisconnected = ServerDisconnected;
111+
client.MessageReceived = MessageReceived;
112+
client.Start();
116113
}
117-
118114
break;
119115

120116
case "reconnect":
121-
if (client != null)
122-
{
123-
client.Dispose();
124-
}
125-
126-
client = new WatsonTcpClient(serverIp, serverPort)
127-
{
128-
ServerConnected = ServerConnected,
129-
ServerDisconnected = ServerDisconnected,
130-
MessageReceived = MessageReceived,
131-
};
132-
133-
client.Start();
117+
if (client != null) client.Dispose();
118+
client = new WatsonTcpClient(serverIp, serverPort);
119+
client.ServerConnected = ServerConnected;
120+
client.ServerDisconnected = ServerDisconnected;
121+
client.MessageReceived = MessageReceived;
122+
client.Start();
134123
break;
135124

136125
case "psk":
@@ -152,36 +141,22 @@ private static void Main()
152141
}
153142
}
154143

155-
private static void InitializeClient()
156-
{
144+
static void InitializeClient()
145+
{
157146
if (!useSsl)
158147
{
159148
client = new WatsonTcpClient(serverIp, serverPort);
160149
}
161150
else
162151
{
163-
bool provideCertificate = Common.InputBoolean("Do you wish to provide a certificate ? (required for mutual authenication)", true);
152+
certFile = Common.InputString("Certificate file:", "test.pfx", false);
153+
certPass = Common.InputString("Certificate password:", "password", false);
164154
acceptInvalidCerts = Common.InputBoolean("Accept Invalid Certs:", true);
155+
mutualAuthentication = Common.InputBoolean("Mutually authenticate:", true);
165156

166-
if (provideCertificate)
167-
{
168-
certFile = Common.InputString("Certificate file:", "test.pfx", false);
169-
certPass = Common.InputString("Certificate password:", "password", false);
170-
mutualAuthentication = Common.InputBoolean("Mutually authenticate:", true);
171-
172-
client = new WatsonTcpClient(serverIp, serverPort, certFile, certPass)
173-
{
174-
AcceptInvalidCertificates = acceptInvalidCerts,
175-
MutuallyAuthenticate = mutualAuthentication,
176-
};
177-
}
178-
else
179-
{
180-
client = new WatsonTcpClient(Mode.Ssl, serverIp, serverPort, null)
181-
{
182-
AcceptInvalidCertificates = acceptInvalidCerts,
183-
};
184-
}
157+
client = new WatsonTcpClient(serverIp, serverPort, certFile, certPass);
158+
client.AcceptInvalidCertificates = acceptInvalidCerts;
159+
client.MutuallyAuthenticate = mutualAuthentication;
185160
}
186161

187162
client.AuthenticationFailure = AuthenticationFailure;
@@ -196,45 +171,41 @@ private static void InitializeClient()
196171
client.Start();
197172
}
198173

199-
private static string AuthenticationRequested()
174+
static string AuthenticationRequested()
200175
{
201-
Console.WriteLine(String.Empty);
202-
Console.WriteLine(String.Empty);
176+
Console.WriteLine("");
177+
Console.WriteLine("");
203178
Console.WriteLine("Server requests authentication");
204179
Console.WriteLine("Press ENTER and THEN enter your preshared key");
205-
if (String.IsNullOrEmpty(presharedKey))
206-
{
207-
presharedKey = Common.InputString("Preshared key:", "1234567812345678", false);
208-
}
209-
180+
if (String.IsNullOrEmpty(presharedKey)) presharedKey = Common.InputString("Preshared key:", "1234567812345678", false);
210181
return presharedKey;
211182
}
212183

213-
private static bool AuthenticationSucceeded()
184+
static bool AuthenticationSucceeded()
214185
{
215186
Console.WriteLine("Authentication succeeded");
216187
return true;
217188
}
218189

219-
private static bool AuthenticationFailure()
190+
static bool AuthenticationFailure()
220191
{
221192
Console.WriteLine("Authentication failed");
222193
return true;
223194
}
224195

225-
private static bool MessageReceived(byte[] data)
196+
static bool MessageReceived(byte[] data)
226197
{
227198
Console.WriteLine("Message from server: " + Encoding.UTF8.GetString(data));
228199
return true;
229200
}
230201

231-
private static bool ServerConnected()
202+
static bool ServerConnected()
232203
{
233204
Console.WriteLine("Server connected");
234205
return true;
235206
}
236207

237-
private static bool ServerDisconnected()
208+
static bool ServerDisconnected()
238209
{
239210
Console.WriteLine("Server disconnected");
240211
return true;

0 commit comments

Comments
 (0)