This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TM4C1294NCPDT:TM4C1294NCPDT 的 WebSocket 客户端库/示例

Guru**** 2611705 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1015294/tm4c1294ncpdt-websocket-client-library-example-for-tm4c1294ncpdt

器件型号:TM4C1294NCPDT

我需要将电路板连接到正在工作的 WebSocket 服务器。我可以握手、但当我使用 TCP 将数据发送到服务器时、其中包含所有 WebSocket 标志。它不会升级到 WebSocket、并且有效载荷作为 TCP 请求工作。 请建议一种方法、以便在握手完成后可以将数据发送到 WebSocket 上的服务器。握手已完成。我正在共享 Wireshark 日志。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    内部32_t
    WeatherForecast(TWeatherSource eWeatherSource, const char *pcQuery,
    tWeatherReport *psWeatherReport,tEventFunction pfnEvent)

    int32_t i32Idx;
    // const char pcCount[]="&cnt=1;

    //
    //如果请求的源无效或没有回拨
    //只是失败。
    //
    // if ((eWeatherSource!= iWSrcOpenWeatherMap)||(g_sWeather.pfnEvent))
    //{
    //返回(-1);
    //}
    if (eWeatherSource!= iWSrcOpenWeatherMap)

    if (g_sWeather.pfnEvent)

    返回(-1);


    G_sWeather.pfnEvent = pfnEvent;
    G_sWeather.psWeatherReport = psWeatherReport;

    // if (g_Senet.Estate == iEthNoConnection) return (0);
    //
    //连接或重新连接到端口80。
    //
    // g_Senet.Estate = iEthTCPConnectWait;

    //
    //将基本预测请求复制到缓冲区。
    //
    // i32Idx = MergeRequest1 (0、g_cWeatherRequestForecast、
    // sizeof (g_cWeatherRequestForecast);

    //
    //追加请求。
    //
    //i32Idx = MergeRequest1 (i32Idx、pcQuery、sizeof (g_sWeather.pcRequest));

    //
    //添加请求模式。
    //
    // i32Idx = MergeRequest1 (i32Idx、g_cMode、sizeof (g_cMode));

    //
    //追加计数。
    //
    //i32Idx = MergeRequest1 (i32Idx、pcCount、sizeof (pcCount));

    //
    //添加应用程序 ID。
    //
    // i32Idx = MergeRequest1 (i32Idx、g_cAPPIDOpenHeather、
    // sizeof (g_cAPPIDOpenWeather);

    //
    //添加"HTTP:/1.1"字符串。
    //
    // i32Idx = MergeRequest1 (i32Idx、g_cHTTP11、sizeof (g_cHTTP11));
    // UARTprintf ("\n\t%s"、g_sWeather.pcRequest);
    //
    //强制气象报告请求。
    //
    // g_Senet.ulRequest = weather_forecast;
    // i32Idx = MergeRequest1 (0、get、sizeof (get));
    i32Idx = MergeRequest1 (0、webpack、sizeof (webpack));
    ProcessTransmit.TransmitLength = ReqFunctions[ProcessTransmit.TransmitIndex[e_IdCallResult]]();
    i32Idx = MergeRequest1 (i32Idx、Response、ProcessTransmit.TransmitLength);

    if (WebSocket。HandshakeInprogress=1)

    i32Idx = MergeRequest1 (0、cmd_1、sizeof (cmd_1));
    i32Idx = MergeRequest1 (i32Idx、cmd_2、sizeof (cmd_2));
    i32Idx = MergeRequest1 (i32Idx、cmd_3、sizeof (cmd_3));
    i32Idx = MergeRequest1 (i32Idx、cmd_4、sizeof (cmd_4));
    i32Idx = MergeRequest1 (i32Idx、cmd_5、sizeof (cmd_5));
    i32Idx = MergeRequest1 (i32Idx、cmd_6、sizeof (cmd_6));

    /*
    i32Idx = MergeRequest1 (i32Idx、webpack、sizeof (webpack));
    ProcessTransmit.TransmitLength = ReqFunctions[ProcessTransmit.TransmitIndex[e_IdCallResult]]();
    i32Idx = MergeRequest1 (i32Idx、Response、ProcessTransmit.TransmitLength);
    *

    if (EthClientTCPConnect (3002)!= ERR_OK)

    return(-1);

    //
    //保存请求的大小。
    //
    G_sWeather.ui32RequestSize = i32Idx;

    返回(0);

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    这是我使用的代码、此代码根据 enet_weather 示例代码进行修改。

    我需要在 TCP 和 HTTP 工作正常的现有项目中实施 WebSocket。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Pradeep、

     抱歉、我们完全没有 WebSocket 协议的相关经验。 我建议您使用 Wireshark 捕获网络流量、以了解与 HTTP 协议相比、将会发生什么情况。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    好的,查尔斯比我要好,解决了这个问题。