views:

43

answers:

1

Following on this question: http://stackoverflow.com/questions/3143075/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!

A: 

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.

Jon Skeet
Sorry, I did not post the full code. Before that code I do this:sBuffer = sBuffer + "HTTP/1.1 200 OK"; sBuffer = sBuffer + "Content-Type: text/xml; charset=utf-8"; sBuffer = sBuffer + "Content-Length: 1";and send that sBuffer.Also after that I do close the socket. When I test that same mobile app with something online it does work so it must be something my windows "Server" program is doing wrong. p.s. all firewalls etc are off
Matt
note that HTTP headers are separated by the line breaks and you don't seem to be doing that
liho1eye