Message broadcasting over internet
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Message broadcasting over internet

  1. #1
    Join Date
    Jun 2010
    Posts
    6

    Message broadcasting over internet

    Hi

    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
    void brodcast()
    {
    Socket sock = new Socket(AddressFamily.Unspecified, SocketType.Dgram,
    ProtocolType.Udp);
    IPEndPoint iep1 = new IPEndPoint(IPAddress.Broadcast, 9050);
    string hostname = Dns.GetHostName();
    byte[] data = Encoding.ASCII.GetBytes(hostname);
    sock.SetSocketOption(SocketOptionLevel.Socket,
    SocketOptionName.Broadcast, 1);
    sock.SendTo(data, iep1);
    sock.Close();
    }


    Below code at client
    void listenTobroadcast()
    {
    string mcastGroup = "224.5.6.7";
    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.Bind(ipep);

    s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 0);

    IPAddress ip = IPAddress.Parse(mcastGroup);

    s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, IPAddress.Broadcast);

    while (true)
    {
    byte[] b = new byte[5000];
    Console.WriteLine("Waiting for data..");
    s.Receive(b);
    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

  2. #2

    Re: Message broadcasting over internet

    UDP Multicasting must be enabled on every single router that the messages are trying to cross, which makes UDP multicasting pretty much useless except for Peer Networks.

  3. #3
    Join Date
    Jun 2010
    Posts
    6

    Re: Message broadcasting over internet

    Hi Matthew

    Thank you for your reply.

    So you think i can't complete my requirement. Can you suggest me any other way to do the things
    Last edited by nmkishan22; June 24th, 2010 at 05:14 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center