471,337 Members | 978 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to use 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 10.154.0.104:554 to
224.1.2.3:554.
How can I get the data at 224.1.2.3:554 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)?

Thanks.

--------------------------

Here's a simple code that blocks:

public MulticastServer(int localPort)
{
socket=new
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);
socket.Bind(ep);
}

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];
Array.Copy(buffer,0,packet,0,receivedBytes);
return packet;
}

Jan 17 '06 #1
0 1497

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Fred Palmer | last post: by
7 posts views Thread by Jim H | last post: by
1 post views Thread by Nuno Magalhaes | last post: by
reply views Thread by Nuno Magalhaes | last post: by
reply views Thread by zig158 | last post: by
1 post views Thread by Jayme.Pechan | last post: by
2 posts views Thread by =?Utf-8?B?aXdkdTE1?= | 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.