using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace HttpServer
{
    public partial class Form1 : Form
    {
        private string szLocalIP = "192.168.1.189";
       //private string szLocalPort = "18887";
        //private int nLocalPort = 18887;
        /*
        private int nLocalPort = 18887;
        private int nDevicePort = 9998;
        private int WaitTimout = 3000;
        */
        public Form1()
        {
            InitializeComponent();

            InitNetSDK();
        }
        private List<string> GetHostIPAddress()
        {
            List<string> lstIPAddress = new List<string>();
            IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ipa in IpEntry.AddressList)
            {
                if (ipa.AddressFamily == AddressFamily.InterNetwork)
                    lstIPAddress.Add(ipa.ToString());
            }
            return lstIPAddress; // result: 192.168.1.17 ......
        }
        private void InitNetSDK()
        {
            List<string> color;
            color = GetHostIPAddress();
            System.String[] IPstr = { };  //color.Count
            IPstr = color.ToArray();

            int nLocalDex = 0;
            for (int kk = 0; kk < IPstr.Count(); kk++)
            {
                comBoxLocalIP.Items.Add(IPstr[kk]);
            }
            nLocalDex = 0;
            comBoxLocalIP.SelectedIndex = nLocalDex;
            szLocalIP = comBoxLocalIP.SelectedItem.ToString();

        }

        private void comBoxLocalIP_SelectedIndexChanged(object sender, EventArgs e)
        {
            szLocalIP = comBoxLocalIP.SelectedItem.ToString();
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            int port = 18887;//80 //8080
            port = int.Parse(textBox1.Text.ToString());
            Button2.Enabled = false;
            MyHttpServer httpServer = new MyHttpServer(10);
            httpServer.Start(port);
        }

    }
}
