/// <summary> /// Connects to the Minecraft Server. /// </summary> /// <param name="ip">The IP of the server to connect to</param> /// <param name="port">The port of the server to connect to</param> public void Connect(string ip, ushort port) { ServerHost = ip; ServerPort = port; // -- Connect to the server and begin reading packets. _networkHandler.Connect(ip, port); }
protected virtual async void Start() { var token = this.GetCancellationTokenOnDestroy(); await UniTask.Run(_networkHandler.Initialize, cancellationToken : token); onConnectCommand.Subscribe(() => { if (connectionStatusVariable == ConnectionStatusEnum.Disconnected) { connectionStatusVariable.Value = ConnectionStatusEnum.Connecting; _networkHandler.Connect(address).Forget(); } }) .AddTo(token); onDisconnectCommand.Subscribe(async() => { await _networkHandler.Disconnect(); connectionStatusVariable.Value = ConnectionStatusEnum.Disconnected; }) .AddTo(token); if (stringMessageSender != null) { stringMessageSender .Where(_ => connectionStatusVariable == ConnectionStatusEnum.Connected) .Subscribe(_networkHandler.SendString) .AddTo(token); } if (byteMessageSender != null) { byteMessageSender .Where(_ => connectionStatusVariable == ConnectionStatusEnum.Connected) .Subscribe(_networkHandler.SendBytes) .AddTo(token); } }