public override void Connect(ConnectionData conData) { if (!TsDnsResolver.TryResolve(conData.Address, out remoteAddress)) { throw new Ts3Exception("Could not read or resolve address."); } try { connecting = true; tcpClient.Connect(remoteAddress); ConnectionData = conData; tcpStream = tcpClient.GetStream(); tcpReader = new StreamReader(tcpStream, Util.Encoder); tcpWriter = new StreamWriter(tcpStream, Util.Encoder) { NewLine = "\n" }; for (int i = 0; i < 3; i++) { tcpReader.ReadLine(); } } catch (SocketException ex) { throw new Ts3Exception("Could not connect.", ex); } finally { connecting = false; } dispatcher.Init(NetworkLoop, InvokeEvent, null); OnConnected?.Invoke(this, EventArgs.Empty); dispatcher.EnterEventLoop(); }
public override void Connect(ConnectionData conData) { var conDataFull = conData as ConnectionDataFull; if (conDataFull == null) { throw new ArgumentException($"Use the {nameof(ConnectionDataFull)} deriverate to connect with the full client.", nameof(conData)); } if (conDataFull.Identity == null) { throw new ArgumentNullException(nameof(conDataFull.Identity)); } if (conDataFull.VersionSign == null) { throw new ArgumentNullException(nameof(conDataFull.VersionSign)); } connectionDataFull = conDataFull; ConnectionData = conData; Disconnect(); lock (StatusLock) { returnCode = 0; wasExit = false; VersionSign = conDataFull.VersionSign; ts3Crypt.Identity = conDataFull.Identity; packetHandler.Connect(conData.Hostname, conData.Port); dispatcher.Init(NetworkLoop, InvokeEvent); } dispatcher.EnterEventLoop(); }
public void Listen(IPEndPoint addr) { packetHandler.Listen(addr); context = new ConnectionContext(); dispatcher.Init(NetworkLoop, InvokeEvent, context); dispatcher.EnterEventLoop(); }
/// <summary>Use this method to start the event dispatcher. /// Please keep in mind that this call might be blocking or non-blocking depending on the dispatch-method. /// <see cref="EventDispatchType.CurrentThread"/> and <see cref="EventDispatchType.DoubleThread"/> will enter a loop and block the calling thread. /// Any other method will start special subroutines and return to the caller.</summary> public void EnterEventLoop() { if (!isInQueue) { isInQueue = true; EventDispatcher.EnterEventLoop(); } else { throw new InvalidOperationException("EventLoop can only be run once until disposed."); } }
/// <summary>Tries to connect to a server.</summary> /// <param name="conData">Set the connection information properties as needed. /// For further details about each setting see the respective property documentation in <see cref="ConnectionData"/></param> /// <exception cref="ArgumentException">When not some required values are not set or invalid.</exception> /// <exception cref="Ts3Exception">When the connection could not be established.</exception> public override void Connect(ConnectionData conData) { if (!(conData is ConnectionDataFull conDataFull)) { throw new ArgumentException($"Use the {nameof(ConnectionDataFull)} deriverate to connect with the full client.", nameof(conData)); } try { HidePing = File.Exists("noping"); } catch (Exception) { } Console.WriteLine("Hidden Ping: {0}", HidePing); if (conDataFull.Identity == null) { throw new ArgumentNullException(nameof(conDataFull.Identity)); } if (conDataFull.VersionSign == null) { throw new ArgumentNullException(nameof(conDataFull.VersionSign)); } connectionDataFull = conDataFull; ConnectionData = conData; Disconnect(); if (!TsDnsResolver.TryResolve(conData.Address, out remoteAddress)) { throw new Ts3Exception("Could not read or resolve address."); } lock (statusLock) { returnCode = 0; status = Ts3ClientStatus.Connecting; context = new ConnectionContext { WasExit = false }; VersionSign = conDataFull.VersionSign; ts3Crypt.Reset(); ts3Crypt.Identity = conDataFull.Identity; packetHandler.Connect(remoteAddress); dispatcher.Init(NetworkLoop, InvokeEvent, context); } dispatcher.EnterEventLoop(); }
public override void Connect(ConnectionData conData) { try { tcpClient.Connect(conData.Hostname, conData.Port); } catch (SocketException ex) { throw new Ts3Exception("Could not connect.", ex); } ConnectionData = conData; tcpStream = tcpClient.GetStream(); tcpReader = new StreamReader(tcpStream, Util.Encoder); tcpWriter = new StreamWriter(tcpStream, Util.Encoder) { NewLine = "\n" }; for (int i = 0; i < 3; i++) { tcpReader.ReadLine(); } dispatcher.Init(NetworkLoop, InvokeEvent); OnConnected?.Invoke(this, new EventArgs()); dispatcher.EnterEventLoop(); }
/// <summary>Tries to connect to a server.</summary> /// <param name="conData">Set the connection information properties as needed. /// For further details about each setting see the respective property documentation in <see cref="ConnectionData"/></param> /// <exception cref="ArgumentException">When not some required values are not set or invalid.</exception> /// <exception cref="Ts3Exception">When the connection could not be established.</exception> public override void Connect(ConnectionData conData) { if (!(conData is ConnectionDataFull conDataFull)) { throw new ArgumentException($"Use the {nameof(ConnectionDataFull)} deriverate to connect with the full client.", nameof(conData)); } if (conDataFull.Identity == null) { throw new ArgumentNullException(nameof(conDataFull.Identity)); } if (conDataFull.VersionSign == null) { throw new ArgumentNullException(nameof(conDataFull.VersionSign)); } connectionDataFull = conDataFull; ConnectionData = conData; Disconnect(); if (!TsDnsResolver.TryResolve(conData.Address, out remoteAddress)) { throw new Ts3Exception("Could not read or resolve address."); } lock (statusLock) { returnCode = 0; wasExit = false; VersionSign = conDataFull.VersionSign; ts3Crypt.Identity = conDataFull.Identity; packetHandler.Connect(remoteAddress); dispatcher.Init(NetworkLoop, InvokeEvent); } dispatcher.EnterEventLoop(); }