Hi, guys.

I'm hoping you can help me. I've been a coder a long time, but I just never have done anything with events and delegates. I have a rough understanding of the concept, but am having trouble using it in my particular application, which deals with socket messaging. Could someone help me plug in what goes where, in my code below?

In my server app, which listens on a port, I have a string I need to throw back to the client using an event, but I am not sure how to do that. Here is a subset of my code:

while (true) {
bytes_received = listener.Receive (ref groupEP);
string FullMsg = Encoding.Default.GetString (bytes_received, 0, bytes_received.Length);
message = Encoding.ASCII.GetString (bytes_received, 0, bytes_received.Length);

// I want to return message back to the client program, but am not sure how.


I have my delegate and event set up at the beginning of the code like this:

public delegate void MessageReceivedHandler(string message);
public event MessageReceivedHandler MessageReceived;

So I hate to ask someone to just help me fill out this code, but I think if I could see a working example in my own code, it would make more sense to me. All the examples I find online are just too complex or specialized.

Thanks so much for any help, guys.