public void BeginReceive()
        {
            List <string> address = ToolForIp.getLocalAddress();

            if (address.Count == 0)
            {
                return;
            }
            foreach (string _address in address)
            {
                SocketUDP client = new SocketUDP(_address, clientPort);
                client.Ac_ReceiveMsg += AC_ReceiveMsgCallBack;

                lock (clientDic)
                {
                    addClient(_address, client);
                }

                LogUtil.InfoFormat("{0} 开始侦听...", _address);
                if (msgCallback != null)
                {
                    msgCallback(string.Format("{0} 开始侦听...", _address));
                }
                client.SyncReceiveMessage();
            }
        }
 public ServerController(int serverPort)
 {
     this.port = serverPort;
     this._ip  = IPAddress.Any.ToString();
     _server   = new SocketUDP(_ip, port);
     init();
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            //ISocket testSocket = new SocketTCP();
            ISocket testSocket = new SocketUDP();

            testSocket.RunSocket();

            Console.ReadKey();
        }
        private void SendToServer(Data data)
        {
            if (serverIp == null)
            {
                return;
            }
            SocketUDP udp = getSocket(serverIp);

            udp.Send(data, serverIp);
        }
 private void addClient(string ip, SocketUDP udp)
 {
     lock (clientDic)
     {
         string id = ToolForIp.getChildIp(ip, 3);
         if (!clientDic.ContainsKey(id))
         {
             clientDic.Add(id, udp);
         }
     }
 }