简体   繁体   English

使用JScript进行端口侦听

[英]Port listening with JScript

I'm Trying to write a plugin for NotePad++ using NppScripting - a platform for writing plugins using javascript (specifically - JScript). 我正在尝试使用NppScripting为NotePad ++编写插件-一种使用javascript(特别是JScript)编写插件的平台。

I was wondering if there was a way (probably via ActiveXObject) with which I could listen to a port asynchronously (specifically - I'm trying to write a CSS-X-Fire port to NPP). 我想知道是否有一种方法(可能通过ActiveXObject)可以异步侦听端口(特别是-我正在尝试将CS​​S-X-Fire端口写入NPP)。

I know .NET has that capability via System.Net.Sockets but I couldn't figure out a way to access it via JScript. 我知道.NET通过System.Net.Sockets具有该功能,但我想不出一种通过JScript访问它的方法。

Any help? 有什么帮助吗?

If I were doing this, I would write the Socket server in .NET as a standalone EXE. 如果这样做,我将在.NET中将套接字服务器编写为独立的EXE。 If I understand CSS-X-Fire correctly, it is a plugin to IntelliJ Idea that listens to outgoing communications from Firebug, and then updates source files appropriately. 如果我正确理解CSS-X-Fire,则它是IntelliJ Idea的插件,可侦听Firebug的传出通信,然后适当地更新源文件。 It sounds relatively simple. 听起来比较简单。 The .NET socket server could do this very easily. .NET套接字服务器可以很容易地做到这一点。

Then, rather than expose a 2nd interface directly from the socket server to the scripting environment - like a COM object or a COPYDATA channel or something like that - I'd use the filesystem for communication. 然后,我将使用文件系统进行通信,而不是将第二个接口直接从套接字服务器公开到脚本环境(例如COM对象或COPYDATA通道等)。 In other words, script something in NPP that polls the filesystem file for updates. 换句话说,在NPP中编写脚本以轮询文件系统文件以获取更新。 When the .NET Socket server gets a message that says "Firebug just updated file X.css", the .NET Socket server can apply those updates to the filesystem file, and save changes back to the filesystem. 当.NET套接字服务器收到一条消息“ Firebug刚刚更新了文件X.css”时,.NET套接字服务器可以将这些更新应用于文件系统文件,并将更改保存回文件系统。 Because the Notepad++ app polls the filesystem, it will see the updated file and reload it, picking up those saved changes. 由于Notepad ++应用程序轮询文件系统,因此它将看到更新的文件并重新加载它,并选择保存的更改。 You'd need to do cursor management within N++ intelligently. 您需要在N ++中智能地进行游标管理。

Emacs has an "auto revert mode" for this sort of thing, so the .NET CSS-X-Fire Socket server would work with emacs out of the box - no additional scripting required. Emacs针对这种情况提供了“自动还原模式”,因此.NET CSS-X-Fire Socket服务器可以直接使用emacs进行工作-无需其他脚本。 Not sure if N++ has an auto-revert equivalent. 不确定N ++是否具有等效的自动还原。

I eventually decided to use Adobe AIR to create my solution. 我最终决定使用Adobe AIR来创建我的解决方案。 It provides an amazing set of APIs, including a set of Socket APIs. 它提供了一组惊人的API,包括一组Socket API。

You can look at my solution here 你可以在这里看看我的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM