Skip to content

Commit 6fc869f

Browse files
committed
Making the behavior consistent with the behavior of WebSocket4Net
i.e. we don't catch exceptions that the user throws and that make their program crash
1 parent ea9e421 commit 6fc869f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/net45/Extensions/WampSharp.WebSockets/WebSockets/WebSocketWrapperConnection.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ private ArraySegment<byte> GetMessageInBytes(WampMessage<object> message)
5353
protected abstract WebSocketMessageType WebSocketMessageType { get; }
5454

5555
protected async void Connect()
56+
{
57+
bool connected = await TryConnect();
58+
59+
if (connected)
60+
{
61+
await Task.Run(this.RunAsync, mCancellationToken).ConfigureAwait(false);
62+
}
63+
}
64+
65+
private async Task<bool> TryConnect()
5666
{
5767
try
5868
{
@@ -61,13 +71,15 @@ await this.ClientWebSocket.ConnectAsync(mAddressUri, mCancellationToken)
6171

6272
RaiseConnectionOpen();
6373

64-
Task task = Task.Run(this.RunAsync, mCancellationToken);
74+
return true;
6575
}
6676
catch (Exception ex)
6777
{
6878
RaiseConnectionError(ex);
6979
RaiseConnectionClosed();
7080
}
81+
82+
return false;
7183
}
7284

7385
public IClientWebSocketWrapper ClientWebSocket => mWebSocket as IClientWebSocketWrapper;

0 commit comments

Comments
 (0)