sendto 无法在 VxWorks 上运行

发布于 2024-09-27 14:03:11 字数 1285 浏览 4 评论 0原文

我之前问过这个问题,但没有解决(仍然有问题)。我很困惑,因为函数返回时没有错误,并且没有发送数据!此代码在 Linux 上工作... VxWorks 版本不起作用(sendto 不发送,但它返回时没有错误)。

概要 - 我正在编写一个简单的回显服务器 - 服务器成功接收 数据(来自 x86 盒子)并声称已成功将其发送回。 但是,客户端(x86 上的 netcat)上未收到任何数据。这 代码正在 PowerPC 机上的 VxWorks 5.4 上运行...

  • 我是否正在以某种方式缓冲 UDP 数据?

  • 是否有其他任务阻止 sendto 发送? (不是在这里白费力气,而是我以正常优先级生成我的应用程序,即低于网络任务等关键任务......所以这很好)。

  • VxWorks 可以缓冲我的 UDP 数据吗?

  • 我已经设置了我的路由表... ping 有效!

  • 没有防火墙据我所知...

  • sendto 的细微差别是什么以及什么会阻止我的数据 到达客户...

    while(1)
    {
    readlen = recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *) &client_address, &slen);

    if (readlen == ERROR)
    {
        printf("RECVFROM FAILED()/n");
        return (ERROR);
    }

    printf("Received %d bytes FROM %s:%d\nData: %s\n\n",
           readlen, inet_ntoa(client_address.sin_addr),
    ntohs(client_address.sin_port), buf);

    // Send it to right back to the client using the open UDP socket
    // but send it to OUTPORT
    client_address.sin_port = htons(OUTPORT);

    // Remember slen is a value (not an address ... in, NOT in-out)
    sendlen = sendto(sock, buf, BUFLEN, 0, (struct sockaddr*)&client_address, slen);

    // more code ....
   }

I asked this question before and had no resolution (still having the problem). I am stumped because the function returned without error and NO DATA was sent! This code works on Linux ... the VxWorks version does not work (sendto does not send, though it returns without an ERROR).

The synopsis - I am writing a simple echo server - The server successfully receives
the data (from an x86 box) and claims it successfully SENT it back.
However NO DATA is received on the client (netcat on an x86). This
code is running on VxWorks 5.4 on a PowerPC box ...

  • I is the UDP data being buffered somehow?

  • Could another task be preventing sendto from sending? (NOT to get off on a wild goose chase here, but I taskspawn my application with a normal priority, i.e. below critical tasks like the network task etc etc ... so this is fine).

  • Could VxWorks be buffering my UDP data?

  • I HAVE setup my routing table ... pinging works!

  • There is NO firewall AFAIK ...

  • What are the nuances of sendto and what would prevent my data from
    reaching the client ...

    while(1)
    {
    readlen = recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *) &client_address, &slen);

    if (readlen == ERROR)
    {
        printf("RECVFROM FAILED()/n");
        return (ERROR);
    }

    printf("Received %d bytes FROM %s:%d\nData: %s\n\n",
           readlen, inet_ntoa(client_address.sin_addr),
    ntohs(client_address.sin_port), buf);

    // Send it to right back to the client using the open UDP socket
    // but send it to OUTPORT
    client_address.sin_port = htons(OUTPORT);

    // Remember slen is a value (not an address ... in, NOT in-out)
    sendlen = sendto(sock, buf, BUFLEN, 0, (struct sockaddr*)&client_address, slen);

    // more code ....
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橪书 2024-10-04 14:03:11

我相信 ERROR 被定义为 -1,对吧?那么您是否检查 sendto(2) 调用? errno(3)< 怎么样? /code>值?

我在代码中看到的一个明显问题是,您将 BUFLEN 作为要发送的消息的长度,而实际上应该是 readlen - 您收到的字节数。

I trust ERROR is defined as -1, right? Then are you checking the return value of the sendto(2) call? What about the errno(3) value?

One obvious problem I see in the code is that you give BUFLEN as length of the message to be sent, while it should actually be readlen - the number of bytes you received.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文