All pastes #586435 Raw Edit

Miscellany

public text v1 · immutable
#586435 ·published 2007-06-23 20:53 UTC
rendered paste body
public Image loadImage(DateTime time)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            sock.Connect("192.168.1.12", 80);

            string year = curdate.Year.ToString();
            year = year.Substring(year.Length - 2);
            string month = curdate.Month.ToString().PadLeft(2, '0');
            string day = curdate.Day.ToString().PadLeft(2, '0');

            string header = "GET /garfield/garfield_coll/ga" + year + month + day + ".gif HTTP/1.0\r\n";
            header += "Host: 192.168.1.12\r\n\r\n";

            textBox1.Text = "Sending request:\r\n\r\n" + header + "?";

            sock.Send(Encoding.ASCII.GetBytes(header));
            textBox1.Text += ("Request sent...\r\n");

            byte[] bbuffer = new byte[sock.ReceiveBufferSize];

            sock.Receive(bbuffer);
            textBox1.Text += ("Reply received...\r\n");

            MemoryStream mstream;

            char[] reply = Encoding.ASCII.GetChars(bbuffer);
            string replystr = new string(reply);

            Regex rg = new Regex("\\r\\n\\r\\n");
            MatchCollection mc = rg.Matches(replystr);
            int i = mc[0].Index;

            mstream = new MemoryStream();
            mstream.Write(bbuffer, i, bbuffer.Length - i);
            sock.Disconnect(false);
            return Image.FromStream(mstream);
        }