diff --git a/CoreRemoting/Channels/Websocket/WebsocketClientChannel.cs b/CoreRemoting/Channels/Websocket/WebsocketClientChannel.cs
index b91d86e..b182053 100644
--- a/CoreRemoting/Channels/Websocket/WebsocketClientChannel.cs
+++ b/CoreRemoting/Channels/Websocket/WebsocketClientChannel.cs
@@ -144,6 +144,7 @@ await WebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure,
LastException = ex as NetworkException ??
new NetworkException(ex.Message, ex);
+ ErrorOccured?.Invoke(ex.Message, ex);
Disconnected?.Invoke();
}
finally
@@ -169,6 +170,8 @@ public bool SendMessage(byte[] rawMessage)
{
LastException = ex as NetworkException ??
new NetworkException(ex.Message, ex);
+
+ ErrorOccured?.Invoke(ex.Message, ex);
return false;
}
}
diff --git a/CoreRemoting/Channels/Websocket/WebsocketConnection.cs b/CoreRemoting/Channels/Websocket/WebsocketConnection.cs
index da58159..4143ffc 100644
--- a/CoreRemoting/Channels/Websocket/WebsocketConnection.cs
+++ b/CoreRemoting/Channels/Websocket/WebsocketConnection.cs
@@ -24,8 +24,6 @@ public WebsocketConnection(HttpListenerWebSocketContext websocketContext, WebSoc
RemotingServer = remotingServer ?? throw new ArgumentNullException(nameof(remotingServer));
}
- public Guid Guid { get; } = Guid.NewGuid();
-
private HttpListenerWebSocketContext WebSocketContext { get; set; }
private WebSocket WebSocket { get; set; }
@@ -74,16 +72,17 @@ public bool SendMessage(byte[] rawMessage)
///
/// Starts listening to the incoming messages.
///
- public void StartListening()
+ public Guid StartListening()
{
- CreateRemotingSession();
+ var sessionId = CreateRemotingSession();
_ = ReadIncomingMessages();
+ return sessionId;
}
///
/// Creates for the incoming websocket connection.
///
- private void CreateRemotingSession()
+ private Guid CreateRemotingSession()
{
byte[] clientPublicKey = null;
@@ -98,6 +97,8 @@ private void CreateRemotingSession()
Session = RemotingServer.SessionRepository.CreateSession(
clientPublicKey, RemotingServer, this);
+
+ return Session.SessionId;
}
private async Task ReadIncomingMessages()
diff --git a/CoreRemoting/Channels/Websocket/WebsocketServerChannel.cs b/CoreRemoting/Channels/Websocket/WebsocketServerChannel.cs
index 717d8b8..2ceaa18 100644
--- a/CoreRemoting/Channels/Websocket/WebsocketServerChannel.cs
+++ b/CoreRemoting/Channels/Websocket/WebsocketServerChannel.cs
@@ -60,8 +60,8 @@ private async Task ReceiveConnection()
var connection = new WebsocketConnection(websocketContext, websocket, Server);
// handle incoming websocket messages
- Connections[connection.Guid] = connection;
- connection.StartListening();
+ var sessionId = connection.StartListening();
+ Connections[sessionId] = connection;
}
///
diff --git a/CoreRemoting/CoreRemoting.csproj b/CoreRemoting/CoreRemoting.csproj
index e74b7f6..bb93697 100644
--- a/CoreRemoting/CoreRemoting.csproj
+++ b/CoreRemoting/CoreRemoting.csproj
@@ -58,7 +58,7 @@
-
+