Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8776545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:05:08+00:00 2026-06-13T19:05:08+00:00

Hello i got this code from here to receive data on a multicast address

  • 0

Hello i got this code from here to receive data on a multicast address

 Socket sock = new Socket(AddressFamily.InterNetwork,
            SocketType.Dgram, ProtocolType.Udp);
 Console.WriteLine("Ready to receive…");
 IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9050);
 EndPoint ep = (EndPoint)iep;
 sock.Bind(iep);
 sock.SetSocketOption(SocketOptionLevel.IP, 
            SocketOptionName.AddMembership, 
            new MulticastOption(IPAddress.Parse("224.100.0.1")));
 byte[] data = new byte[1024];
 int recv = sock.ReceiveFrom(data, ref ep);
 string stringData = Encoding.ASCII.GetString(data, 0, recv);
 Console.WriteLine("received: {0} from: {1}", stringData, ep.ToString());
 sock.Close();

Now this works when i receive a packet, then the sock.ReceiveFrom is triggered but after that the receiver shuts down (even if i remove the sock.Close line).
What i want is that the receiver displays or saves me the data but continue listening for more packets.

What would be a good way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:05:09+00:00Added an answer on June 13, 2026 at 7:05 pm

    You have to code some kind of loop or use the async methods BeginReceive/EndReceive.
    As soon as your local sock variable gets out of scope, it might be collected by gc and get disposed.

    byte[] data = new byte[1024];
    
    while (true) {
        // this blocks until some bytes are received
        int recv = sock.ReceiveFrom(data, ref ep);
        string stringData = Encoding.ASCII.GetString(data, 0, recv);
        Console.WriteLine("received: {0} from: {1}", stringData, ep.ToString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this piece of code from a Backbone.js tutorial from here . The
I got this code ` // // prints out Hello World! // hello_world(); //First
I got this code in my submit form <form id=myform action='hello.php' method='GET'> <input type=button
I got this program from GroovyConsole . I'm reproducing here for easy reference, def
hello can anyone see what is wrong with this regex? i got it from
Hallo all. I got this piece of code: <div> <input id=id1 name=radioButton type=radio> <input
Hello I've got this query to get users by email, which is an unique
I just did a syntax like this mysql_real_escape_string($var = 'Hello'); print_r($var); and I got
I'm stuck with this pretty silly thing; I got a textfile like this; Hello::140.0::Bye
Hello got the error in following code.. The method RefeshDataGridView() is static.I run it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.