Events don't work with C#

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Events don't work with C#

Re: Events don't work with C#

by mcow » Wed Jul 20, 2011 10:54 am

I've put up a sample Python script in the wiki that demonstrates event handling from an external program.

Re: Events don't work with C#

by mcow » Tue Jul 19, 2011 1:32 pm

Whoops; my mistake. Python has a "MakePy" utility which builds Python wrappers for COM objects, and I had failed to rebuild it for MM4. So, the MM3 interface was still being used, which of course did not have the support for the event objects.
I've rebuilt it now, and it's working fine. Sorry for the noise!

Re: Events don't work with C#

by jitterjames » Tue Jul 19, 2011 1:01 pm

Yes they work fine with C#, but only in MM4. I have not tried with python. I'm not too familiar with python, using it only when I need a script in EventGhost.

Re: Events don't work with C#

by mcow » Tue Jul 19, 2011 12:43 pm

The short Python demo program I provided uptopic does not work with MM4 1408.

@jitterjames, have you had any luck getting events to work with MM4?

Re: Events don't work with C#

by jiri » Sun Jun 05, 2011 1:47 pm

Since version 4.0 is very close to being released, we probably won't make any 3.x updates. This one doesn't look like a good candidate anyway, since it would require quite some testing in order to rule out regressions.

Jiri

Re: Events don't work with C#

by jitterjames » Sun Jun 05, 2011 1:41 pm

that's wonderful. thanks. Does this mean that there will be no more updates for MM version 3?

If there are future updates, would/could this issue be fixed in MM3?

Re: Events don't work with C#

by jiri » Sun Jun 05, 2011 1:15 pm

yes

Re: Events don't work with C#

by jitterjames » Sun Jun 05, 2011 8:20 am

does this mean that events should now work with version 4.0.0.1384 (Developer build) found here:?

http://www.mediamonkey.com/forum/viewto ... ta#p300010

Re: Events don't work with C#

by jitterjames » Fri Jun 03, 2011 5:52 am

cool. good news. Thanks!

Re: Events don't work with C#

by jiri » Fri Jun 03, 2011 4:42 am

Thanks all for the feedback, I have reviewed the implementation and fixed the issues with MM server created from external applications - it will be fixed in the next MM 4.0 build.

Jiri

Re: Events don't work with C#

by jitterjames » Fri May 27, 2011 11:08 am

I don't know what more I can tell you. It works perfectly with VoxCommando and EventGhost and you have access to the listener code used in both cases.

Here's the code that sends the udp message in c#

Code: Select all

public static void sendMessage(string mymessage, int port)
        {
            UdpClient udp = new UdpClient();
            
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Parse("255.255.255.255"), port);
            
            byte[] sendBytes4 = Encoding.Default.GetBytes(mymessage);
            udp.Send(sendBytes4, sendBytes4.Length, groupEP);
            udp.Close();
        }

Re: Events don't work with C#

by mcow » Fri May 27, 2011 10:30 am

I'm still not able to get that working. What protocol do you specify when you create your outgoing socket? I selected UDP in my receiver socket.

However, I don't need it. I've created a named-pipe implementation that works pretty well. I'm still bugfixing and polishing, but it's solved my basic problem. I can now write a Python script (or really, any program) that can attach to the pipe and get a string identifying each event as it happens.

The named-pipe is implemented as a COM object (which needs to be registered), also written in Python but it gets loaded in-proc by a VBS; then each event-handler just dumps the string into the pipe. If there's no client on the other end of the pipe, nothing gets written.

Re: Events don't work with C#

by jitterjames » Thu May 26, 2011 6:43 am

it broadcasts to all ip addresses. you should be able to listen on any ip address as long as it belongs to the adapter which is on the same lan. You need to be listening on the correct port though. In the case of my example:

Code: Select all

WShell.Run("""" & SDB.ApplicationPath & "Scripts\Auto\udpsender.exe"" 33000 " & strEvent),0,1
the port is 33000. Of course you can change that to something else if you want.

For example python code look at the broadcaster plugin for eventghost. It works with my MM script and the udpsender.exe

this is my c# code:

Code: Select all

void udpListenerThread(object sender, DoWorkEventArgs e)
        {                              
            int listenPort = 33000;
            try
            {
                UdpClient listener = new UdpClient(listenPort);
                IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);

                while (true)
                {
                    byte[] bytes = listener.Receive(ref groupEP);
                    string rawtext = Encoding.ASCII.GetString(bytes, 0, bytes.Length);

                    udpresult = rawtext;
                    backgroundWorkerUDP.ReportProgress(10);
                }
            }
            catch
            {
                voxLogger.writeLine("error opening UDP listening port.  It may already be in use.");
                return;
            }
        }

Re: Events don't work with C#

by mcow » Wed May 25, 2011 11:50 pm

@jitterjames: I'm trying to use your udp scheme, but I'm not getting the messages to my port. I can reach it from another Python program.
What IP addr does udpsender.exe send to? I'm not seeing data come in on 127.0.0.1 nor on my ethernet adapter.

Re: Events don't work with C#

by Melloware » Thu May 19, 2011 5:50 am

mcow wrote: @melloware, I don't think you're using the term "out-of-proc" correctly. The app code may reside somewhere random, but once MM instantiates the object, it's in-proc—that is, the code is running within the MediaMonkey process.
You are correct it is in-process inside the MediaMonkey process which I stated 3 posts above. quoted:

I based my MonkeyTunes plugin on the same architecture (in C# instead of VB) and it works great. It is a lot of trouble to go through but it is the only way to get in-process calls in your plugin. Since the script instantiates your C# app as a COM object the COM runs in-process with the main MM process and thus is handed the events from the SDB object already running in the script engine.

Top