using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using ToolKitlib;
using System.Net.Sockets;
using System.Net;

namespace DianBiao
{
    class Dianbiao
    {
        static log4net.ILog log;//日志插件

        public static Socket udpServer;//udp服务器
        public static bool memberReply;//是否回复消息
        public static int length = 0;//接收数据长度

        public static EndPoint serverEnd; //服务端
        public static IPEndPoint ipEnd; //发送消息服务端
        public static Socket socket; //目标socket
        public static Thread connectThread; //连接线程
        public static byte[] sendData;//发送的数据

        static void Main(string[] args)
        {
            //初始化日志
            log4net.Config.XmlConfigurator.Configure();
            log = log4net.LogManager.GetLogger("loginfo");
            init();
            while (true)
            {
                Thread.Sleep(10000);
            }
        }


        private static void init()
        {
            try
            {
                //var IP = "111.229.30.246";

                var IP = "172.17.0.9";
                //string IP = "172.16.1.49";
                int Port = 12302;

                //建立udp服务器，参数2：udp协议以数据报的方式传输，参数3：UDP协议
                udpServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                //为服务器绑定IP
                IPAddress ip = IPAddress.Parse(IP);
                EndPoint ep = new IPEndPoint(ip, Port);
                udpServer.Bind(ep);
                //接收数据
                EndPoint endP = new IPEndPoint(IPAddress.Any, 0);

                string message;
                byte[] data = new byte[1024 * 1024 * 2];
                length = 0;
                //把数据的来源放到第二个参数上
                while (true)
                {
                    length = udpServer.ReceiveFrom(data, ref endP);
                    //message = Encoding.Default.GetString(data, 0, length);
                    message = ToolKit.byteArrayToHexString(data, length);
                    log.Info("接收到 " + endP.ToString() + ":   " + message);
                    message = message.Replace(" ", "");



                }
            }
            catch (Exception e)
            {

                Console.WriteLine("接收初始化:" + e.Message);
            }

        }


        S
    }
}
