June 23rd, 2010, 02:16 AM
Message broadcasting over internet
I'm screwed up in a problem from last 2 days. Can any one come up with a solution for me?
My problem is
I have a server application which has to boadcast messages over internet. My client program need to trace those messages. Its only one way.
Currently i'm using below code at server to broad cast
Socket sock = new Socket(AddressFamily.Unspecified, SocketType.Dgram,
IPEndPoint iep1 = new IPEndPoint(IPAddress.Broadcast, 9050);
string hostname = Dns.GetHostName();
byte data = Encoding.ASCII.GetBytes(hostname);
Below code at client
string mcastGroup = "188.8.131.52";
string port = "5000";
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, int.Parse(port));
s.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, 1);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 0);
IPAddress ip = IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, IPAddress.Broadcast);
byte b = new byte;
Console.WriteLine("Waiting for data..");
string str = System.Text.Encoding.ASCII.GetString(b, 0, b.Length);
Console.WriteLine(str.Replace('\0', ' ').Trim());
application work fine within the network. But i wanted this to work over internet any system running client application need to receive the message.
Advanced thanks for help. Waiting for early reply
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!