471,354 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Using ReceiveFrom To Capture Multicast Data

The MSDN says that I have to bind the socket on a local address to use
ReceiveFrom function. How can I bind the socket on a multicast address
in order to get the multicast data.
Say that I want to receive data that is sent from to
How can I get the data at since this is a multicast
address, and using ReceiveFrom? Where do I bind my socket (I have to
bind it to a local IP otherwise gives invalid address)?



Here's a simple code that blocks:

public MulticastServer(int localPort)
Socket(AddressFamily.InterNetwork,SocketType.Dgram ,ProtocolType.Udp);
IPHostEntry IPHost=Dns.GetHostByName(Dns.GetHostName());
IPAddress ip=IPAddress.Parse(IPHost.AddressList[0].ToString());
IPEndPoint ep=new IPEndPoint(ip,localPort);

public byte[] ReceiveFrom(string ipAddress,int port)
//if(socket.Available==0)return null;
IPEndPoint ep=new IPEndPoint(IPAddress.Any,0);
EndPoint ep2=(EndPoint)ep;
byte[] buffer=new byte[1500];
int receivedBytes=socket.ReceiveFrom(buffer,ref ep2);
byte[] packet=new byte[receivedBytes];
return packet;

Jan 17 '06 #1
0 1375

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dan Rice | last post: by
7 posts views Thread by psk | last post: by
7 posts views Thread by Jim H | last post: by
10 posts views Thread by feel52 | last post: by
1 post views Thread by Nuno Magalhaes | last post: by
reply views Thread by zig158 | last post: by
2 posts views Thread by =?Utf-8?B?aXdkdTE1?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.