void Connect() { try { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.BeginConnect(new IPEndPoint(IPAddress.Parse(ipAddress), port), new AsyncCallback(AcceptConnection), socket); } catch (Exception ex) { Console.WriteLine("ClientNet: 1. " + ex.Message); StopClientThread(); statusMethod?.Invoke(false); } }
void ConnectToDB() { try { connection = new MySqlConnection(connectionString.ConnectionString); connection.Open(); Console.WriteLine("DataBaseNet: SQL Connection status: " + connection.State); isConnected = true; statusMethod?.Invoke(isConnected); } catch (MySqlException ex) { isConnected = false; statusMethod?.Invoke(isConnected); Console.WriteLine("DatabaseNet: " + ex.Message); } }
public void Start(StatusMethod _statusMethod = null) { if (!isRunning) { isRunning = true; statusMethod = _statusMethod; StartClientThread(); } else { Console.WriteLine("ClientNet: Server already running"); _statusMethod?.Invoke(false); } }