当前位置: 首页>>代码示例>>C#>>正文


C# UdpClient.JoinMulticastGroup方法代码示例

本文整理汇总了C#中UdpClient.JoinMulticastGroup方法的典型用法代码示例。如果您正苦于以下问题:C# UdpClient.JoinMulticastGroup方法的具体用法?C# UdpClient.JoinMulticastGroup怎么用?C# UdpClient.JoinMulticastGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UdpClient的用法示例。


在下文中一共展示了UdpClient.JoinMulticastGroup方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReceiveData

    // receive thread
    private void ReceiveData()
    {
        client = new UdpClient();

        IPEndPoint localEp = new IPEndPoint(IPAddress.Any, port);
        client.Client.Bind(localEp);

        client.JoinMulticastGroup(IPAddress.Parse(MULTICAST_ADDR));
        while (true)
        {
            try
            {
                byte[] data = client.Receive(ref localEp);
                string text = Encoding.UTF8.GetString(data);
                string[] message = text.Split(',');
                Vector3 result = new Vector3(float.Parse(message[0]), float.Parse(message[1]), float.Parse(message[2]));

                print(">> " + result);

                lastReceivedUDPPacket = result;
            }
            catch (Exception err)
            {
                print(err.ToString());
            }
        }
    }
开发者ID:intel-cornellcup,项目名称:mini-modbot-simulation,代码行数:28,代码来源:UDPReceive.cs

示例2: StartBroadcast

    IEnumerator StartBroadcast()
    {
        // multicast send setup
        udp_client = new UdpClient ();
        udp_client.JoinMulticastGroup (group_address);
        IPEndPoint remote_end = new IPEndPoint (group_address, startup_port);

        // sends multicast
        while (true)
        {
            byte[] buffer = Encoding.ASCII.GetBytes ("GameServer");
            udp_client.Send (buffer, buffer.Length, remote_end);

            yield return new WaitForSeconds (1);
        }
    }
开发者ID:philipcass,项目名称:NetworkingDemo,代码行数:16,代码来源:DiscoverMonoBehaviour.cs

示例3: broadcast

	void broadcast(string message) {
		// multicast send setup
		udp_client = new UdpClient ();
		udp_client.JoinMulticastGroup (group_address);
		remote_end = new IPEndPoint (group_address, port);

		byte[] buffer = Encoding.ASCII.GetBytes (message);
		udp_client.Send (buffer, buffer.Length, remote_end);
	}
开发者ID:bosung90,项目名称:MadScientist,代码行数:9,代码来源:CMMulticastSender.cs

示例4: StartListen

    void StartListen()
    {
        // multicast receive setup
        remote_end = new IPEndPoint (IPAddress.Any, port);
        udp_client = new UdpClient (remote_end);
        udp_client.JoinMulticastGroup (group_address);

        // async callback for multicast
        udp_client.BeginReceive (new AsyncCallback (ReceiveAnnounceCallback), null);
    }
开发者ID:bosung90,项目名称:MadScientist,代码行数:10,代码来源:CMMulticastListener.cs

示例5: DiscoveryManager

 public DiscoveryManager()
 {
     ActivityServices = new List<ServiceInfo>();
     DiscoveryType = DiscoveryType.WsDiscovery;
     #if ANDROID
     _messageId = Guid.NewGuid().ToString();
     _udpClient = new UdpClient(WsDiscoveryPort);
     _udpClient.JoinMulticastGroup(IPAddress.Parse(WsDiscoveryIPAddress));
     _udpClient.BeginReceive(HandleRequest, _udpClient);
     #endif
 }
开发者ID:NikolajLund,项目名称:NooSphere,代码行数:11,代码来源:DiscoveryManager.cs

示例6: RecieveCandidates

    void RecieveCandidates()
    {
        IPEndPoint remote_end = new IPEndPoint (IPAddress.Any, startup_port);
        UdpClient udp_client = new UdpClient (remote_end);
        udp_client.JoinMulticastGroup (group_address);

        UdpState s = new UdpState();
        s.e = remote_end;
        s.u = udp_client;

        // async callback for multicast
        udp_client.BeginReceive (new AsyncCallback (ServerLookup), s);
    }
开发者ID:philipcass,项目名称:NetworkingDemo,代码行数:13,代码来源:ElectDiscover.cs

示例7: Main

	public static void Main ()
	{
		var ip = IPAddress.Parse ("239.255.255.250");
		while (true) {
			UdpClient udp = new UdpClient (3802);
			udp.JoinMulticastGroup (ip, 1);
			IPEndPoint dummy = null;
			udp.Receive (ref dummy);
			Console.WriteLine ("Received");
			udp.DropMulticastGroup (ip);
			udp.Close ();
		}
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:13,代码来源:udp-direct-svc.cs

示例8: SendCandidate

    IEnumerator SendCandidate()
    {
        // multicast send setup
        UdpClient udp_client = new UdpClient ();
        udp_client.JoinMulticastGroup (group_address);
        IPEndPoint remote_end = new IPEndPoint (group_address, startup_port);

        // sends multicast
        while (true)
        {
            byte[] buffer = Encoding.ASCII.GetBytes (SystemInfo.deviceUniqueIdentifier);
            udp_client.Send (buffer, buffer.Length, remote_end);
            yield return new WaitForSeconds (1);
        }
    }
开发者ID:philipcass,项目名称:NetworkingDemo,代码行数:15,代码来源:ElectDiscover.cs

示例9: Main

	static int Main (string [] args)
	{
		int port = 8001;
		UdpClient udpClient = new UdpClient (port);
		IPAddress ip = IPAddress.Parse ("224.0.0.2");
		udpClient.JoinMulticastGroup (ip, IPAddress.Any);
		udpClient.MulticastLoopback = true;
		udpClient.Ttl = 1;
		udpClient.BeginReceive (ReceiveNotification, udpClient);
		udpClient.Send (new byte [1] { 255 }, 1, new IPEndPoint (ip, port));
		System.Threading.Thread.Sleep (1000);
		udpClient.DropMulticastGroup (ip);
		if (!_receivedNotification)
			return 1;
		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:16,代码来源:test.cs

示例10: ListenWorker

    void ListenWorker(Action<byte[]> callback, string address, int port)
    {
        using (UdpClient listener = new UdpClient(port))
        {
            IPAddress addr = IPAddress.Parse(address);
            IPEndPoint ep = new IPEndPoint(addr, port);
            listener.JoinMulticastGroup(addr);

            //listener.Client.ReceiveBufferSize = 16*4096;

            Debug.Log("Listening on " + address + ":" + port.ToString());
            List<byte> lastData = new List<byte>();
            while (!die)
            {
                byte[] data = listener.Receive(ref ep);
                received += data.Length;
                byte[] before;
                byte[] after;
                FindBeforeAndAfterSignal(data, out before, out after);
                bool send = (lastData != null && before == null) || (before != null && before.Length != data.Length);

                if (before != null)
                    lastData.AddRange(before);

                if (send)
                {
                    if (lastData != null && lastData.Count > 0)
                    {
                        callback(lastData.ToArray());
                    }

                    if (after != null)
                        lastData = new List<byte>(after);
                    else
                        lastData = new List<byte>();
                }
            }
        }
    }
开发者ID:Garufortho,项目名称:TestJunk,代码行数:39,代码来源:MulticastListener.cs

示例11: Initialize

  }//Terminate()

  public static void Initialize() 
  {
    //
    // instantiate UdpCLient
    //
    
    m_Client = new UdpClient(LocalPort);

    //
    // Create an object for Multicast Group
    //

    m_GroupAddress = IPAddress.Parse("224.0.0.1");
    //
    // Join Group
    //
    try 
    {
      m_Client.JoinMulticastGroup(m_GroupAddress, 100);
    }//try
    catch(Exception e) 
    {
      Console.WriteLine("Unable to join multicast group: {0}", e.ToString());
    }//catch

    //
    // Create Endpoint for peer
    //
    m_RemoteEP = new IPEndPoint(m_GroupAddress, RemotePort);

  }//Initialize()
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:33,代码来源:udpchat.cs

示例12: OpenMulticastSocket

		private async Task OpenMulticastSocket(HostInfo hostInfo, bool ipv6)
		{
			if (group == null)
			{
				// TODO: not going to resolve this, just going to set it directly
				//group = Dns.Resolve(DNSConstants.MDNS_GROUP).AddressList[0];
				group = IPAddress.Parse(ipv6 ? DNSConstants.MDNS_GROUP_IPV6 : DNSConstants.MDNS_GROUP);
			}
			if (socket != null)
			{
				await this.CloseMulticastSocket();
			}
			socket = new UdpClient(DNSConstants.MDNS_PORT);
            await socket.Bind();

			socket.JoinMulticastGroup((IPAddress) group, 255);
		}
开发者ID:pisker,项目名称:mDNS,代码行数:17,代码来源:mDNS.cs

示例13: StartGameClient

    void StartGameClient()
    {
        // multicast receive setup
        IPEndPoint remote_end = new IPEndPoint (IPAddress.Any, startup_port);
        udp_client = new UdpClient (remote_end);
        udp_client.JoinMulticastGroup (group_address);

        // async callback for multicast
        udp_client.BeginReceive (new AsyncCallback (ServerLookup), null);

        StartCoroutine(MakeConnection ());
    }
开发者ID:philipcass,项目名称:NetworkingDemo,代码行数:12,代码来源:DiscoverMonoBehaviour.cs

示例14: WriteWorker

    void WriteWorker(string address, int port)
    {
        using (UdpClient writer = new UdpClient())
        {
            var ip = IPAddress.Parse(address);
            writer.JoinMulticastGroup(ip);
            //writer.Client.SendBufferSize = 16*4096;
            var ipEndPoint = new IPEndPoint(ip, port);

            Debug.Log("writing to " + address + ":" + port.ToString());

            writer.Send(signal, signal.Length, ipEndPoint);

            while (!die)
            {
                byte[] next = null;
                lock(toSendLock)
                if (toSend.Count > 0)
                {
                    next = toSend.Pop();
                }
                if (next != null)
                {
                    Debug.Log("Sending data " + next.Length);
                    //writer.BeginSend(next, next.Length, null, null);

                    for(int i = 0; i < next.Length; i += 1024)
                    {
                        int amount = i < next.Length - 1024 ? 1024 : next.Length - i;
                        byte[] send = new byte[amount];
                        System.Array.Copy(next, i, send, 0, amount);
                        writer.Send(send, send.Length, ipEndPoint);
                        sent += amount;
                    }

                    //writer.Send(next, next.Length, ipEndPoint);
                }

                Thread.Sleep(50);
            }
        }
    }
开发者ID:Garufortho,项目名称:TestJunk,代码行数:42,代码来源:MulticastWriter.cs


注:本文中的UdpClient.JoinMulticastGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。