I read the msdn tutorial for using socket with Windows phone. (http://msdn.microsoft.com/en-us/library/system.net.sockets.socket(v=VS.96).aspx) I arrived to connect me to the server.
This, return me an response 200 ( OK response ) =>
HTTP/1.1 200 OK
Date: Mon, 16 Apr 2012 12:45:46 GMT
Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny13 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g
Last-Modified: Tue, 08 Aug 2006 14:12:09 GMT
ETag: "129a2e5-100000-41a822e23a040"
Accept-Ranges: byte
But I don’t know what to do next…
I connect me to the server, I sent this a “GET Message” for download a file
"GET /dwn/file.txt HTTP/1.1\r\nHost:myHost.com\r\n\r\n"
and After the response ? I have to do what?
If you know a tutorial, sample, or just explication, I would thank you greatly!
this my function =>
private void ProcessReceive(SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
response = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred);
response = response.Trim('\0');
// show the response server value.
Debug.WriteLine(response.ToString());
// Data has now been sent and received from the server.
// Disconnect from the server
socket = e.UserToken as Socket;
socket.Shutdown(SocketShutdown.Send);
socket.Close();
clientDone.Set();
}
else
{
// show error in the debugger.
response = e.SocketError.ToString();
Debug.WriteLine(response);
}
}
Why don’t you use WebClient or something like that ?
If it’s just for experiencing, you should know that this is not a trivial task. Here are some hints:
Have fun !
Edit
Clarifications (point #1):
Why do you shutdown and close the socket now? The response body follows the header in the stream. As I said, there is probably more bytes waiting to be received from the server. Continue to call “receive” until either: