Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Event Listener Creation

$
0
0
Hello!

Here's a JavaScript sample that works and is very similar to your C# code:
using (var engine = new V8ScriptEngine()) {
    engine.AddHostObject("host", new HostFunctions());
    engine.AddHostType(typeof(UdpClient));
    engine.AddHostType(typeof(IPEndPoint));
    engine.AddHostType(typeof(IPAddress));
    engine.AddHostType(typeof(Encoding));
    engine.AddHostType(typeof(Console));
    engine.Execute(@"
        _lst = new UdpClient(4567);
        var groupEp = host.newVar(new IPEndPoint(IPAddress.Any, 4567));
        try {
            while (true) {
                var bytes = _lst.Receive(groupEp.ref);
                Console.WriteLine(Encoding.ASCII.GetString(bytes, 0, bytes.Length));
            }
        }
        catch (ex) {
            Console.WriteLine(ex.hostException);
        }
    ");
}
Good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>