mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
the connection was re-estabilished after a "connection forcibly closed by the server" but the following communication was not succesfully because the session contained dirty information as well as the sendCounter in TcpTransport.
this commit fixes this situation, so a connection can be succesfully re-enstabilished and the communication restarted.
This commit is contained in:
parent
2bcae5bd9b
commit
5778366b29
|
|
@ -37,8 +37,10 @@ namespace TLSharp.Core.Network
|
|||
tcpClient.Close();
|
||||
}
|
||||
tcpClient = new TcpClient(ipAddress.AddressFamily);
|
||||
sendCounter = 0;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
await tcpClient.ConnectAsync(ipAddress, port);
|
||||
} catch (Exception ex) {
|
||||
throw new Exception ($"Problem when trying to connect to {ipAddress}:{port}; either there's no internet connection or the IP address version is not compatible (if the latter, consider using DataCenterIPVersion enum)",
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ namespace TLSharp.Core
|
|||
private List<TLDcOption> dcOptions;
|
||||
private TcpClientConnectionHandler handler;
|
||||
private DataCenterIPVersion dcIpVersion;
|
||||
private ISessionStore store;
|
||||
string sessionUserId;
|
||||
|
||||
public Session Session
|
||||
{
|
||||
|
|
@ -56,15 +58,15 @@ namespace TLSharp.Core
|
|||
if (string.IsNullOrEmpty(apiHash))
|
||||
throw new MissingApiConfigurationException("API_HASH");
|
||||
|
||||
if (store == null)
|
||||
store = new FileSessionStore();
|
||||
this.store = store ?? new FileSessionStore();
|
||||
this.sessionUserId = sessionUserId;
|
||||
|
||||
this.apiHash = apiHash;
|
||||
this.apiId = apiId;
|
||||
this.handler = handler;
|
||||
this.dcIpVersion = dcIpVersion;
|
||||
|
||||
session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
||||
session = Session.TryLoadOrCreateNew(this.store, sessionUserId);
|
||||
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +75,12 @@ namespace TLSharp.Core
|
|||
token.ThrowIfCancellationRequested();
|
||||
|
||||
if (!transport.IsConnected)
|
||||
{
|
||||
// we must recreate the session because it might track dirty information
|
||||
// of a connection that maybe was disconnected, reusing that session will cause errors
|
||||
session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
||||
await transport.Connect();
|
||||
}
|
||||
if (!transport.IsConnected)
|
||||
throw new Exception("Connection to Telegram failed");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue