Comments (5)
I hope you can work with this
Yeah thats exactly what I was requesting. Why not make a pull request and get it added to the library?
from teamspeak3queryapi.
I will make a pull request if I am finished with fixing all problems. There are also a problem if the user is banned. There will be no QueryExecaption casted. Currently in my project I added the whole source and not the package to develop live with the source. I just read this issue and create you fast fix 👍
from teamspeak3queryapi.
why not make a loop that checks if the bool function IsConnected() of TeamSpeakClient.Client is false?
from teamspeak3queryapi.
why not make a loop that checks if the bool function IsConnected() of TeamSpeakClient.Client is false?
I tried that at first, didn't work.
Right now my workaround is to simply send "version" command on a 4 minute timer, to make sure it doesn't idle kick me.
That has ran flawlessly for weeks now.
from teamspeak3queryapi.
Hey @dedmen ,
there is a much smarter solution by just added the event. You just need to add your QueryClient.cs like this.
Adding the Eventhandler
public class QueryClient : IDisposable
{
public EventHandler OnConnectionLost;
/// <summary>Gets the remote host of the Query API client.</summary>
/// <returns>The remote host of the Query API client.</returns>
public string Host { get; }
Adding the firing method
After that you need to create the virtual method the fire the event. I´ve added this code before the constructors but it doesen´t matter where you add it.
#region Events
public virtual void EventConnectionLost(EventArgs e)
{
OnConnectionLost?.Invoke(this, e);
}
#endregion
Firing the method if the connection is lost
Now you just need to fire the method if the client lost the connection. That on line 407. There you just type EventConnectionLost(EventArgs.Empty);
. But to be sure here is the whole class of ResponseProcessingLoop
private CancellationTokenSource ResponseProcessingLoop()
{
var cts = _cts = new CancellationTokenSource();
Task.Run(async () =>
{
while (!cts.Token.IsCancellationRequested)
{
string line = null;
try
{
line = await _reader.ReadLineAsync().WithCancellation(cts.Token).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
break;
}
Debug.WriteLine(line);
if (line == null)
{
cts.Cancel();
continue;
}
if (string.IsNullOrWhiteSpace(line))
continue;
var s = line.Trim();
if (s.StartsWith("error", StringComparison.OrdinalIgnoreCase))
{
Debug.Assert(_currentCommand != null);
var error = ParseError(s);
_currentCommand.Error = error;
InvokeResponse(_currentCommand);
}
else if (s.StartsWith("notify", StringComparison.OrdinalIgnoreCase))
{
s = s.Remove(0, "notify".Length);
var not = ParseNotification(s);
InvokeNotification(not);
}
else
{
Debug.Assert(_currentCommand != null);
_currentCommand.RawResponse = s;
_currentCommand.ResponseDictionary = ParseResponse(s);
}
}
IsConnected = false;
EventConnectionLost(EventArgs.Empty);
});
return cts;
}
That´s it. Now you can easy check for a lost connection without traffic waste 👍 . Now to be fair here is my example how I check the connection.
Example
_client.Client.OnConnectionLost += async (sender, e) =>
{
Log.Error($"Instance {Instance.Alias}: Verbindung zum Server verloren...");
Log.Error($"Instance {Instance.Alias}: Verbindungsversuch wird in {TIME_TO_RETRY} erneut versucht...");
await Task.Delay(TIME_TO_RETRY);
_ = Connect();
};
I hope you can work with this :)
from teamspeak3queryapi.
Related Issues (20)
- No responses come through after lots of activity HOT 4
- TeamSpeak3QueryApi.pdb not loaded HOT 2
- Setting channel parent via channeledit does not work, consider removing it. HOT 1
- Not getting any response HOT 8
- SSH Support HOT 5
- Multiple channel notifications problem HOT 8
- Fatal error: Unsubscripe with callback won't work HOT 1
- Adding ssh as nuget package HOT 3
- SendAsync with Parameters and Options don't work HOT 1
- Events occasionally do not fire (ClientLeftView,ClientEnterView,TextMessage) HOT 10
- Feature Request: Automatic Keep-Alive HOT 3
- Get RequestedTalkPower of Client HOT 1
- Migrate to GH Actions HOT 1
- Adding Talkpower Serialization
- TeaSpeak connection was refused at .Connect(); HOT 1
- GetClients returns empty list in TextMessage notification
- Migrate to more recent .NET version HOT 10
- Unit tests for the query parser
- Improve API documentation HOT 2
- Client times out after 5 mins HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from teamspeak3queryapi.