/// This method does not block.
/// </summary>
/// <param name="bytes">The bytes of data to send in the handshake.</param>
- /// <param name="timeout">The number of milliseconds to wait before giving up on the connect attempt.</param>
- public abstract void ConnectAsync(byte[] bytes = null, int timeout = 5000);
+ public abstract void ConnectAsync(byte[] bytes = null);
/// <summary>
/// Invokes the DataReceived event.
/// client.
/// </para>
/// <para>
- /// Hazel doesn't store connections so it is your responsibility to keep track of the connections to your
- /// server. Note that as <see cref="Connection"/> implements <see cref="IDisposable"/> if you are not storing
- /// a connection then as a bare minimum you should call <see cref="Connection.Dispose()"/> here in order to
- /// release the connection correctly.
+ /// Hazel may or may not store connections so it is your responsibility to keep track and properly Dispose of
+ /// connections to your server.
/// </para>
/// <include file="DocInclude/common.xml" path="docs/item[@name='Event_Thread_Safety_Warning']/*" />
/// </remarks>
}
}
- /// <summary>
- /// Closes the connection listener safely.
- /// </summary>
- /// <remarks>
- /// Internally this simply calls Dispose therefore trying to reuse the ConnectionListener after calling Close will
- /// cause ObjectDisposedExceptions.
- /// </remarks>
- public virtual void Close()
- {
- Dispose();
- }
-
/// <summary>
/// Call to dispose of the connection listener.
/// </summary>
return this.allConnections.TryRemove(endPoint, out var conn);
}
- /// <inheritdoc />
protected virtual void Dispose(bool disposing)
{
foreach (var kvp in this.allConnections)
/// <remarks>
/// This will always throw a HazelException.
/// </remarks>
- public override void ConnectAsync(byte[] bytes = null, int timeout = 5000)
+ public override void ConnectAsync(byte[] bytes = null)
{
throw new InvalidOperationException("Cannot manually connect a UdpServerConnection, did you mean to use UdpClientConnection?");
}
/// <inheritdoc />
public override void Connect(byte[] bytes = null, int timeout = 5000)
{
- this.ConnectAsync(bytes, timeout);
+ this.ConnectAsync(bytes);
//Wait till hello packet is acknowledged and the state is set to Connected
bool timedOut = !WaitOnConnect(timeout);
}
/// <inheritdoc />
- public override void ConnectAsync(byte[] bytes = null, int timeout = 5000)
+ public override void ConnectAsync(byte[] bytes = null)
{
this.State = ConnectionState.Connecting;
keepAliveTimer = new Timer(
(o) =>
{
+ if (this.State != ConnectionState.Connected) return;
+
if (this.pingsSinceAck >= this.MissingPingsUntilDisconnect)
{
this.DisposeKeepAliveTimer();
}
}
- //Inform the connection of the buffer (new connections need to send an ack back to client)
- connection.HandleReceive(message, bytesReceived);
-
- //If it's a new connection invoke the NewConnection event.
+ // If it's a new connection invoke the NewConnection event.
+ // This needs to happen before handling the message because in localhost scenarios, the ACK and
+ // subsequent messages can happen before the NewConnection event sets up OnDataRecieved handlers
if (!aware)
{
// Skip header and hello byte;
message.Position = 0;
InvokeNewConnection(message, connection);
}
- else if (isHello)
+
+ //Inform the connection of the buffer (new connections need to send an ack back to client)
+ connection.HandleReceive(message, bytesReceived);
+
+ if (aware && isHello)
{
message.Recycle();
}
/// <remarks>
/// This will always throw a HazelException.
/// </remarks>
- public override void ConnectAsync(byte[] bytes = null, int timeout = 5000)
+ public override void ConnectAsync(byte[] bytes = null)
{
throw new InvalidOperationException("Cannot manually connect a UdpServerConnection, did you mean to use UdpClientConnection?");
}
}
/// <inheritdoc />
- public override void ConnectAsync(byte[] bytes = null, int timeout = 5000)
+ public override void ConnectAsync(byte[] bytes = null)
{
this.State = ConnectionState.Connecting;
SendHello(bytes, () =>
{
this.State = ConnectionState.Connected;
- this.InitializeKeepAliveTimer();
});
+
+ this.InitializeKeepAliveTimer();
}
/// <summary>