相关文章推荐
谈吐大方的筷子  ·  self.lstm = ...·  2 月前    · 
高兴的硬币  ·  python处理 yaml ...·  3 月前    · 
没有腹肌的碗  ·  在powershell中将xlsx ...·  1 年前    · 

I use this Microsoft example to build UWP app for Windows IoT Core on C#. I use npm ws client for the browser and the same npm ws for Node.js server. The Server uses standard ping (opcode 0x9) and pong frames.
How to get "ping" from the server in UWP app and how to answer "pong" to it? I cannot find any C# classes to do that.

Thanks for providing the details. I have tested with the Fleck library in my last post. If i send the ping frame, the ws server invokes the message callback(incoming) while not ping callback(heartbeat). In another hand, I also tried with a package named Chilkat.WebSocket, it works fine.

               Chilkat.WebSocket ws = new Chilkat.WebSocket();
                ws.PongAutoConsume = true;
                Chilkat.Rest rest = new Chilkat.Rest();
                bool success = rest.Connect("localhost", 8080, false, false);
                ws.UseConnection(rest);
                ws.AddClientHeaders();
                string responseBodyIgnored = rest.FullRequestNoBody("GET", "/wsChilkatEcho.ashx");
                success = ws.ValidateServerHandshake();
                if (success != true)
                    Console.WriteLine(ws.LastErrorText);
                    return;
                bool finalFrame = false;
                success = ws.SendFrame("This is the 1st frame\r\n", finalFrame);
                if (success != true)
                    Console.WriteLine(ws.LastErrorText);
                    return;
               // Let's send a Ping frame here...
               success = ws.SendPing("This is a ping");
               if (success != true)
                     Console.WriteLine(ws.LastErrorText);
                     return;
						

@Victor Denisenko , a ping or pong is just a regular frame, but it's a control frame. So you can implement getting ping frame or sending pong frame in your websocket server.I don't know how you hosted the websocket server in your UWP app, or what library of websocket server you used. I found out a repo which includes the implements. You can refer to the open source.

If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Thank you, Michael, but I need to refine my question. I use a socket server that has implemented getting ping and pong frames. The library for the socket server is https://www.npmjs.com/package/ws.
For client implementation I use Windows.Networking.Sockets Namespace. This namespace contains MessageWebSocket Class and I use it for communication with the server. I am sending the message as

 using (var dataWriter = new DataWriter(messageWebSocket.OutputStream))
                            dataWriter.WriteString(message);
                            await dataWriter.StoreAsync();
                            dataWriter.DetachStream();

Websockets server obtains this message in javascript event handler

ws.on('message', function incoming(data) {});

But, as for ping, the server is receiving ping in another event:

client.on('ping', function heartbeat() {});

So, my question is, which method I can use to send the ping for receiving it by the server in ping event client.on('ping'...)?
You advise me to implement ping-pong myself, but what classes I need to use to send ping and receive pong in RFC-6455 (websockets standard) compatible way? You advise me Fleck, but this is a server (I need client ) and it works on Windows 7 and Server 2008 hosts, but not on Windows 10 IoT Core, that needs for me.

Thank you for your suggestion. It needs some time to study if Chilkat.WebSocket works on Windows 10 IoT Core. Now I understand that Windows.Networking.Sockets Namespace doesn't contain the ping-pong methods. Because I have already developed a big project using this namespace, it will be better for me to embed my own non-standard ping-pong procedure instead of using Chilkat.WebSocket.
So, I am closing this issue.