本文整理汇总了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());
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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
}
示例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);
}
示例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 ();
}
}
示例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);
}
}
示例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;
}
示例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>();
}
}
}
}
示例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()
示例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);
}
示例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 ());
}
示例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);
}
}
}