Exemplo n.º 1
0
        static void Main(String[] args)
        {
            while(true)
            {
                try
                {
                    Console.Write("Download file: ");
                    String www = Console.ReadLine();
                    www = www.Trim();
                    if(www.StartsWith("http://"))
                        www = www.Substring(7, www.Length - 7);

                    Int32 hostdelim = www.IndexOf('/');
                    String host = www.Substring(0, (hostdelim == -1) ? (www.Length) : (hostdelim));
                    String uri;
                    if(hostdelim == -1)
                        uri = "/";
                    else
                        uri = www.Substring(hostdelim, www.Length - hostdelim);

                    String http = "GET " + uri + " HTTP/1.0\r\n" +
                                  "Host: " + host + "\r\n" +
                                  "\r\n";

                    using(Socket cli = new Socket(AddressFamily.Inet, SocketType.Stream, ProtocolType.Tcp))
                    {
                        cli.Connect(host, 80);

                        cli.Send(http);

                        Byte[] buffer = new Byte[4096];

                        using(FileStream writer = File.OpenWrite("test.html"))
                        {
                            while(true)
                            {
                                Int32 len = cli.Receive(buffer);
                                if(!cli.IsConnected)
                                    break;

                                //Console.Write();
                                writer.Write(buffer, 0, len);
                            }
                        }
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether a <see cref="Socket"/> is in the <see cref="FdSet"/>.
        /// </summary>
        /// <param name="socket">
        /// Type: <see cref="yourmt.Sockets.Socket"/>
        /// The <see cref="Socket"/> to locate in the <see cref="FdSet"/>.
        /// </param>
        /// <returns>
        /// Type: <see cref="System.Boolean"/>
        /// <b>true</b> if <paramref name="socket"/> is found in the <see cref="FdSet"/>; otherwise, <b>false</b>.
        /// </returns>
        public Boolean Contains(Socket socket)
        {
            if(_list.Contains(socket.Handle))
                return true;

            return false;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a <see cref="Socket"/> to the <see cref="FdSet"/>.
 /// </summary>
 /// <param name="socket">
 /// Type: <see cref="yourmt.Sockets.Socket"/>
 /// The <see cref="Socket"/> to be added to the <see cref="FdSet"/>.
 /// </param>
 public void Add(Socket socket)
 {
     _list.Add(socket.Handle);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Removes the first occurrence of a specific <see cref="Socket"/> from the <see cref="FdSet"/>.
 /// </summary>
 /// <param name="socket">
 /// Type: <see cref="yourmt.Sockets.Socket"/>
 /// The <see cref="Socket"/> to remove from the <see cref="FdSet"/>.
 /// </param>
 public void Remove(Socket socket)
 {
     _list.Remove(socket.Handle);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FdSet"/> class that contains the specified <see cref="Socket"/>.
 /// </summary>
 /// <param name="socket">
 /// Type: <see cref="yourmt.Sockets.Socket"/>
 /// The <see cref="Socket"/> which is copied to the new <see cref="FdSet"/>.
 /// </param>
 public FdSet(Socket socket)
 {
     _list = new List<IntPtr>();
     _list.Add(socket.Handle);
 }