protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // Clear all property values that maybe have been set // when the class was instantiated if (LinkClient.Connected) { LinkClient.Stop(); } LinkClient.Dispose(); } // Indicate that the instance has been disposed. _disposed = true; } }
public void Stop() => client.Stop();
static void Main(string[] args) { _ServerIp = InputString("Server IP:", "localhost", true); _ServerPort = InputInteger("Server port:", 9000, true, true); _Ssl = InputBoolean("Use SSL:", false); InitializeClient(); bool runForever = true; while (runForever) { Console.Write("Command [? for help]: "); string userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { continue; } switch (userInput) { case "?": Console.WriteLine("Available commands:"); Console.WriteLine(" ? help (this menu)"); Console.WriteLine(" q quit"); Console.WriteLine(" cls clear screen"); Console.WriteLine(" send text send text to the server"); Console.WriteLine(" send bytes send binary data to the server"); Console.WriteLine(" stats display client statistics"); Console.WriteLine(" status show if client connected"); Console.WriteLine(" dispose dispose of the connection"); Console.WriteLine(" connect connect to the server if not connected"); Console.WriteLine(" reconnect disconnect if connected, then reconnect"); Console.WriteLine(" close close the connection"); break; case "q": runForever = false; break; case "cls": Console.Clear(); break; case "send text": Console.Write("Data: "); userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { break; } if (!_Client.SendAsync(userInput).Result) { Console.WriteLine("Failed"); } else { Console.WriteLine("Success"); } break; case "send bytes": Console.Write("Data: "); userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { break; } if (!_Client.SendAsync(Encoding.UTF8.GetBytes(userInput)).Result) { Console.WriteLine("Failed"); } break; case "stats": Console.WriteLine(_Client.Stats.ToString()); break; case "status": if (_Client == null) { Console.WriteLine("Connected: False (null)"); } else { Console.WriteLine("Connected: " + _Client.Connected); } break; case "dispose": _Client.Dispose(); break; case "connect": if (_Client != null && _Client.Connected) { Console.WriteLine("Already connected"); } else { InitializeClient(); } break; case "reconnect": InitializeClient(); break; case "close": _Client.Stop(); break; default: break; } } }
void OnDestroy() { client.Stop(); }