Example #1
0
 /// <summary>
 /// The stop listen.
 /// </summary>
 /// <param name="socket">
 /// The socket.
 /// </param>
 /// <param name="listenFunc">
 /// The listen func.
 /// </param>
 public static void StopListen(Socket socket, udpReceiver listenFunc)
 {
     lock (ListenFunctions)
     {
         ListenFunctions[socket.LocalEndPoint.ToString()].Remove(listenFunc);
     }
 }
Example #2
0
        /// <summary>
        /// The listen.
        /// </summary>
        /// <param name="ipe">
        /// The ipe.
        /// </param>
        /// <param name="listenFunc">
        /// The listen func.
        /// </param>
        public static void Listen(IPEndPoint ipe, udpReceiver listenFunc)
        {
            var newListenfunction = false;

            lock (ListenFunctions)
            {
                if (ListenFunctions.ContainsKey(ipe.ToString()))
                {
                    ListenFunctions[ipe.ToString()].Add(listenFunc);
                }
                else
                {
                    newListenfunction = true;
                    ListenFunctions.Add(ipe.ToString(), new List <udpReceiver> {
                        listenFunc
                    });
                }
            }

            if (newListenfunction)
            {
                var newListener = new Thread(ListenSocket);
                newListener.IsBackground = true;
                newListener.Start(SocketDict[ipe.ToString()]);

                // ThreadPool.QueueUserWorkItem(ListenSocket, SocketDict[ipe.ToString()]);
            }
        }
Example #3
0
 /// <summary>
 /// The listen.
 /// </summary>
 /// <param name="socket">
 /// The socket.
 /// </param>
 /// <param name="listenFunc">
 /// The listen func.
 /// </param>
 public static void Listen(Socket socket, udpReceiver listenFunc)
 {
     Listen((IPEndPoint)socket.LocalEndPoint, listenFunc);
 }
Example #4
0
 /// <summary>
 /// The listen.
 /// </summary>
 /// <param name="port">
 /// The port.
 /// </param>
 /// <param name="listenFunc">
 /// The listen func.
 /// </param>
 public static void Listen(int port, udpReceiver listenFunc)
 {
     Listen(new IPEndPoint(IPAddress.Any, port), listenFunc);
 }
		/// <summary>
		/// The stop listen.
		/// </summary>
		/// <param name="socket">
		/// The socket.
		/// </param>
		/// <param name="listenFunc">
		/// The listen func.
		/// </param>
		public static void StopListen(Socket socket, udpReceiver listenFunc)
		{
			lock (ListenFunctions)
			{
				ListenFunctions[socket.LocalEndPoint.ToString()].Remove(listenFunc);
			}
		}
		/// <summary>
		/// The listen.
		/// </summary>
		/// <param name="socket">
		/// The socket.
		/// </param>
		/// <param name="listenFunc">
		/// The listen func.
		/// </param>
		public static void Listen(Socket socket, udpReceiver listenFunc)
		{
			Listen((IPEndPoint)socket.LocalEndPoint, listenFunc);
		}
		/// <summary>
		/// The listen.
		/// </summary>
		/// <param name="port">
		/// The port.
		/// </param>
		/// <param name="listenFunc">
		/// The listen func.
		/// </param>
		public static void Listen(int port, udpReceiver listenFunc)
		{
			Listen(new IPEndPoint(IPAddress.Any, port), listenFunc);
		}
		/// <summary>
		/// The listen.
		/// </summary>
		/// <param name="ipe">
		/// The ipe.
		/// </param>
		/// <param name="listenFunc">
		/// The listen func.
		/// </param>
		public static void Listen(IPEndPoint ipe, udpReceiver listenFunc)
		{
			var newListenfunction = false;
			lock (ListenFunctions)
			{
				if (ListenFunctions.ContainsKey(ipe.ToString()))
				{
					ListenFunctions[ipe.ToString()].Add(listenFunc);
				}
				else
				{
					newListenfunction = true;
					ListenFunctions.Add(ipe.ToString(), new List<udpReceiver> { listenFunc });
				}
			}

			if (newListenfunction)
			{
				var newListener = new Thread(ListenSocket);
				newListener.IsBackground = true;
				newListener.Start(SocketDict[ipe.ToString()]);

				// ThreadPool.QueueUserWorkItem(ListenSocket, SocketDict[ipe.ToString()]);
			}
		}