简体   繁体   English

HTML 5 — C#Websocket响应

[英]HTML 5 — C# Websocket response

I'm creating a socket application which is able to receive strings from a websocket within a web page. 我正在创建一个套接字应用程序,它能够从网页内的websocket接收字符串。 I have been able to successfully connect the Websocket to my C# program but when ever the webpage sends a string to the program it seems to be encrypted or hashed in some way. 我已经能够成功地将Websocket连接到我的C#程序,但是无论何时网页向该程序发送一个字符串,它似乎都已经以某种方式被加密或散列了。

For example if the webpage sends "Test" the program would then output "???9uu?\\". 例如,如果网页发送“ Test”,则程序将输出“ ??? 9uu?\\”。 I'm obviously missing a step here and I'm not sure what I should searching for to resolve this issue. 我显然在这里错过了一步,我不确定应该寻找什么来解决此问题。 I'm guessing the string has to be decrypted or put trough a specific function with the TCP key in order to get the actual string? 我猜想字符串必须被解密或使用TCP密钥通过特定功能才能获得实际的字符串?

The code below is the section responsible for receiving the strings from the HTML, (Both "Data" and "MyWriter" output the same string): 下面的代码是负责从HTML接收字符串的部分(“ Data”和“ MyWriter”都输出相同的字符串):

while (true)    
{ 
    CollectedBytes = new byte[128];
    stream.Read(CollectedBytes, 0, CollectedBytes.Length);
    string Data = Encoding.ASCII.GetString(CollectedBytes, 0, CollectedBytes.Length);

    Output.Speak("Message: " + Data);

    StringWriter MyWriter = new StringWriter();
    HttpUtility.HtmlDecode(Data, MyWriter);

    Output.Speak("Message: " + MyWriter.ToString());

    // The word "Test" should output here
    // But instead "???9uu?\" is.
}

I'm assuming that I'm missing a simple step but I've looked everywhere and can't seem to find anything to help me!! 我以为我错过了一个简单的步骤,但是我到处都是,似乎找不到任何可以帮助我的东西! If anyone can give me guidance on what I should do that would be great :) 如果有人可以指导我该怎么做,那太好了:)

Thanks in advance. 提前致谢。

Are you trying to decode data manually without using any WebSocket library? 您是否尝试在不使用任何WebSocket库的情况下手动解码数据? If so, you must know that the payload part of WebSocket frames from clients is masked . 如果是这样,您必须知道来自客户端的WebSocket帧的有效负载部分已被屏蔽 See RFC 6455, 5.3. 参见RFC 6455,5.3。 Client-to-Server Masking . 客户端到服务器的屏蔽

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM