-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I send message to a specificate client? #751
Comments
`server = new WebSocketServer(IPAddress.Any, 8000, true); server.AddWebSocketService("/Web"); server.Log.File = AppDomain.CurrentDomain.BaseDirectory + "/ServerLog.txt"; server.Start(); //Client id from db or file //Message data if (server.WebSocketServices["/Desktop"].Sessions.TryGetSession(clientId, out IWebSocketSession session)) |
wssv.WebSocketServices["/game"].Sessions.Broadcast |
This example is for sending messages to an individual client |
your example to send message to all clients connected to module "/game" |
WriteException.cs
CacheUtil.cs
Chat.cs
How to use it?
Front end request address!
|
Add a timer component to clear the task of closing WebSocket.
|
Hi |
|
I will try to prepare for you a scheme for the implementation of the Chat! |
The case I saw, WebSocket (), is used to send messages to clients, while HttpServer receives messages sent by clients. I only thought of this way to handle it! |
This plan can meet my current needs. |
But I prefer to use only socket for both sides |
Client: |
var client = new WebSocket(ApplicationConfigurations.getConfig("websocket_host")); client.SslConfiguration.ServerCertificateValidationCallback = client.OnOpen += Client_OnOpen; client.Compression = CompressionMethod.Deflate; client.Log.File = AppDomain.CurrentDomain.BaseDirectory + "/WebSocketLog.txt"; client.Connect(); // Events private void Client_OnMessage(object sender, MessageEventArgs e) private void Client_OnClose(object sender, CloseEventArgs e) private void Client_OnError(object sender, WebSocketSharp.ErrorEventArgs e) |
Server (Better implementation in Windows service): |
server = new WebSocketServer(IPAddress.Any, ApplicationConfigurations.getConfig("port").toInt(), true); server.AddWebSocketService("/Chat"); server.Log.File = AppDomain.CurrentDomain.BaseDirectory + "/ServerLog.txt"; server.Start(); |
Chat Behavior: |
class Chat : WebSocketBehavior
} |
My usage scenario is: after the camera captures the license plate, it is written into the database, and then the information is sent to the web end, and then displayed on the web page. There are many users logging in on the web end, and only the administrator role can push it. Administrators can log in from multiple ends and need to push information to each administrator; The plan you gave me is not very suitable for my usage scenario. But I still want to thank you! |
Let's see, I already had a running websocket server. How can I take the initiative to send a message to one of them?
Currently, I can only:
Wait a message from a client and make response, or
Make a broadcast so every client can receive the message.
But what I want is sending to a client its own message by some logic.
Anyone help, please.
The text was updated successfully, but these errors were encountered: