sta / sta/websocket-sharp

Is it possible to limit client session to one?

Open
#519 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

I didn't implement the application i'm now working on, so there is somme things that i d'ont understand wel.

This is how my WebSocket in C# code

public WebSocketServer CurrentWebSocket { get; set; }
...
`
// start the WebSocket
CurrentWebSocket = new WebSocketServer(this.SocketUrl + ":" + this.Port);
CurrentWebSocket.AddWebSocketService("/MyWebSocket");

            if (this.isSecured)
            {
                // Pks or P12 certificates are prefered
                CurrentWebSocket.SslConfiguration.ServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(this.CertificatePath, this.CertificatePassword);
            }

            WebSocketListener.OnMessageReceive += WebSocketListener_OnMessageReceive;
            WebSocketListener.OnOpenReceive += WebSocketListener_OnOpenReceive;
            WebSocketListener.OnErrorReceive += WebSocketListener_OnError;
            WebSocketListener.OnCloseReceive += WebSocketListener_OnCloseReceive;

            CurrentWebSocket.Start();`

Once the WebSocket is started a, application user can connect to it such as:

` // Let us open a web socket
ws = new WebSocket(document.getElementById("url").value);

           ws.onopen = function()
           {
              // Web Socket is connected, send data using send()
				logtext("Connected");
           };
                                           
           ws.onmessage = onreceive;
                                           
           ws.onclose = function()
           { 
              // websocket is closed.
              logtext("Connection is closed..."); 
           };`

The problem i have is that if in my testing page i connect X times to my WebSocket, each after i will send a command i will receive the response from my service X times.

Is it a way to limit my websocket to have a unique session open at a time?

Best regards,
Christophe.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WebSocketServer setup and WebSocketListener event handlers shown in the issue. Trace how each opened connection is handled and how commands produce responses. Done means a second client is rejected or disconnected, so one open session receives each command response once.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.