Web 服务器未返回对 Web 请求的响应

发布于 2024-09-08 03:28:17 字数 677 浏览 5 评论 0原文

接下来这个问题:使用 WebRequest 连接到 Windows 应用 ,我决定在我的客户端应用程序上实现一个简单的 Web 服务器类型的东西来接收 Web 请求。

基本上在客户端应用程序上,我有一个侦听套接字,当它收到连接时,它会对数据执行某些操作,然后返回结果。 接收数据实际上是有效的,但是一旦我处理完数据,我需要将结果发送回发送网络请求的手机。

我尝试使用下面的代码,虽然它确实返回了数据(例如,如果我转到 firefox 中的地址,它会显示成功消息),但它永远不会返回到手机。我不知道哪里出了问题。

if (mySocket.Connected)
{
    if ((numBytes = mySocket.Send(bSendData, bSendData.Length, 0)) == -1)
        listBox1.Items.Add("Socket Error cannot Send Packet");
}

mySocket 是我接收连接的原始套接字。

我需要返回结果的具体方式吗?即使在电话上的回调也不会触发。但我认为我正确地发回了数据,因为网络浏览器确实得到了响应。

谢谢!

Following on this question: Connect to Windows app with WebRequest
, I decided to implement a simple web server type thing on my client app to receive the webrequest's.

Basically on the client app I have a listening socket and when it receives a connection it does something with the data and then returns a result.
Receiving the data actually works, but once I have processed it I need to send a result back to the phone which send the webrequest.

I tried with the code below and although it does return the data(for instance if i goto the address in firefox it displays the success message) it never gets back to the phone. I dont know where it is going wrong.

if (mySocket.Connected)
{
    if ((numBytes = mySocket.Send(bSendData, bSendData.Length, 0)) == -1)
        listBox1.Items.Add("Socket Error cannot Send Packet");
}

and mySocket is the original socket that I received the connection on.

Is there a specific way I need to return the result? The callback even on the phone isnt even firing. But I think I am sending back the data correctly as a webbrowser does get the response.

Thanks!

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

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

发布评论

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

评论(1

百变从容 2024-09-15 03:28:17

您需要在响应中指定内容长度,或者在发送后关闭连接。否则手机不会知道响应已完成。

这可能不是问题所在,但它似乎是一个很有可能的候选者。

You need to either specify the content length in the response, or close the connection after you've sent it. Otherwise the phone won't know that the response has been completed.

That may not be the problem, but it seems like a pretty likely candidate.

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