示例#1
0
 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);
     }
 }
示例#2
0
 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);
     }
 }
示例#3
0
 public void Start(StatusMethod _statusMethod = null)
 {
     if (!isRunning)
     {
         isRunning    = true;
         statusMethod = _statusMethod;
         StartClientThread();
     }
     else
     {
         Console.WriteLine("ClientNet: Server already running");
         _statusMethod?.Invoke(false);
     }
 }