How to make the WebSocketServer server discount a specific user/client?

Hello,

I would like to know what command I can use on the WebSocketServer server to disconnect a specific user after he accepts the connection. For example, if there are 10 users connected to the server, and I want to disconnect a specific one of them, how can I do that?

Hi,

In the current release it's not possible to directly disconnect a client. However we have added a DisconnectClient call similar to SendMessageTo where a callback decides which client should be disconnected. This new method will be part of the next release.

Hi, thanks for getting back to us.

I discovered a problem that if there is some code in the OnDisconnect event with connected users and I order the server to be deactivated "TMSFNCWebSocketServer1.Active := False" it gives an error and the service is blocked, so to solve this I had to put the OnDisconnect event in the OnDisconnect event. test
if (TMSFNCWebSocketServer1.Active) then begin ... end; so for the error, so I would like before disconnecting the server close all connections to avoid this problem.

I would like to ask just one question, why can't the TMSFNCWebSocketServer component be used in a Data Module?

Stopping the server should close all active connections automatically. The client won't be notified because that's how a TCP connection works and WebSocket is based on TCP.

I'm not sure I understand the situation fully. What do you mean by putting the OnDisconnect event in the OnDisconnect event?
A sample or exact steps to reproduce would help to understand this.

Because FNC components are all visual controls which cannot be dropped onto a data module. However, you can still create them programmatically. See here:

Hi, thanks for getting back to us.

I'm posting a video I made here showing the error I mentioned regarding the OnDisconnect event.

Hi,

It looks like you are logging something to a memo from the OnDisconnect? Every event is called from a worker thread. If you are interacting with an UI element then you need to synchronize to the main UI thread.

For that you can put the code inside the OnDisconnect event into a TThread.Synchronize or TThread.Queue call. Alternatively you can enable the AutoSyncEvents property but that will apply to all server events. If OnDisconnect is the only place where you are interacting with UI then I'd suggest to just use TThread.Synchronize/TThread.Queue for that single event.