using System; using System.Text; using System.IO; using System.Net; using System.Net.Sockets; public class HTMLClient { private static Socket ConnectSocket(string server, int port) { Socket s = null; IPHostEntry hostEntry = null; // Získá informace o serveru z DNS hostEntry = Dns.Resolve(server); //TODO: Doplnte kod, kterym otevrete prislusny socket return s; } // This method requests the home page content for the specified server. private static string SocketSendReceive(string server, int port) { string request = "GET / HTTP/1.1\r\nHost: " + server + "\r\nConnection: Close\r\n\r\n"; Byte[] bytesSent = Encoding.ASCII.GetBytes(request); Byte[] bytesReceived = new Byte[256]; //TODO: Doplnte kod, kterym nactete z otevreneho spojeni v metode SocketConnect defaultni stranku. // Az to budete mit, tak metodu a program upravte tak aby mohl stahovat libovolnou existujici stranku. return page; } public static void Main(string[] args) { string host; int port = 80; if (args.Length == 0) //Pokud nejsou žádné parametry, tak použije localhost záznam host = Dns.GetHostName(); else host = args[0]; //Provede samotné načtení kódu HTML stránky, který je defaultní na serveru string result = SocketSendReceive(host, port); Console.WriteLine(result); } }