private void ConnectCallback(IAsyncResult ar) { try { // Complete the connection. ISocketConnection socket = (ISocketConnection)ar.AsyncState; socket.EndConnect(ar); Console.WriteLine("Connected with StellaServer"); _socketConnectionController = new SocketConnectionController <MessageType>(socket, TCP_BUFFER_SIZE); _socketConnectionController.MessageReceived += OnMessageReceived; _socketConnectionController.Disconnect += OnDisconnect; _socketConnectionController.Start(); // Send init SendInit(); } catch (SocketException e) { Console.WriteLine($"Failed to open connection with StellaServer.{e.SocketErrorCode}."); Reconnect(); } }