Hi All,
I'm developing a simple program that send and receive multicast
messages
But it not work correctly... can you help me?
This is my code:
listener:
private IPEndPoint m_ipLocalEndPoi nt = new IPEndPoint(IPAd dress.Any,
4321);
internal void Start()
{
int index = 0;
Socket sock = new Socket(AddressF amily.InterNetw ork,
SocketType.Dgra m, ProtocolType.Ud p);
sock.Bind(m_ipL ocalEndPoint);
EndPoint remoteEndpoint = (EndPoint)m_ipL ocalEndPoint;
while (true)
{
index++;
byte[] byteArray = new byte[512];
int receivedDataLen ght = sock.ReceiveFro m(byteArray,
ref remoteEndpoint) ;
string receivedData =
Encoding.ASCII. GetString(byteA rray, 0, receivedDataLen ght).Trim('\0') ;
System.Diagnost ics.Debug.Write Line(receivedDa ta);
}
}
publisher:
int m_ttl = 1;
public void Send(string pData)
{
Socket socketSender = new
Socket(AddressF amily.InterNetw ork, SocketType.Dgra m, ProtocolType.Ud p);
IPEndPoint ipBroadcastEndP oint = new
IPEndPoint(IPAd dress.Broadcast , m_broadcastPort Number);
string hostname = Dns.GetHostName ();
byte[] data = Encoding.ASCII. GetBytes(hostna me);
socketSender.Se tSocketOption(S ocketOptionLeve l.Socket,
SocketOptionNam e.Broadcast, (int)m_ttl);
socketSender.Se ndTo(toByteArra y(pData),
ipBroadcastEndP oint);
socketSender.Cl ose();
}
Thanks
I'm developing a simple program that send and receive multicast
messages
But it not work correctly... can you help me?
This is my code:
listener:
private IPEndPoint m_ipLocalEndPoi nt = new IPEndPoint(IPAd dress.Any,
4321);
internal void Start()
{
int index = 0;
Socket sock = new Socket(AddressF amily.InterNetw ork,
SocketType.Dgra m, ProtocolType.Ud p);
sock.Bind(m_ipL ocalEndPoint);
EndPoint remoteEndpoint = (EndPoint)m_ipL ocalEndPoint;
while (true)
{
index++;
byte[] byteArray = new byte[512];
int receivedDataLen ght = sock.ReceiveFro m(byteArray,
ref remoteEndpoint) ;
string receivedData =
Encoding.ASCII. GetString(byteA rray, 0, receivedDataLen ght).Trim('\0') ;
System.Diagnost ics.Debug.Write Line(receivedDa ta);
}
}
publisher:
int m_ttl = 1;
public void Send(string pData)
{
Socket socketSender = new
Socket(AddressF amily.InterNetw ork, SocketType.Dgra m, ProtocolType.Ud p);
IPEndPoint ipBroadcastEndP oint = new
IPEndPoint(IPAd dress.Broadcast , m_broadcastPort Number);
string hostname = Dns.GetHostName ();
byte[] data = Encoding.ASCII. GetBytes(hostna me);
socketSender.Se tSocketOption(S ocketOptionLeve l.Socket,
SocketOptionNam e.Broadcast, (int)m_ttl);
socketSender.Se ndTo(toByteArra y(pData),
ipBroadcastEndP oint);
socketSender.Cl ose();
}
Thanks