Socket事件监听器(Titanium Studio Desktop)
我正在使用 Titanium Studio 和稍微修改版本的 corMVC(http://www.bennadel.com/projects/cormvc-jquery-framework.htm) 构建一个桌面应用程序,以将应用程序构建为模型视图控制器。我遇到的问题是套接字监听功能。我想做的是使用相同的函数来侦听不同模型中的传入数据,但每次我在不同的模型中添加新的侦听函数时,如下所示:socket.onRead(readResponse); 它不会覆盖旧函数,因此当服务器向客户端发送数据时,它会发送到所有使用
socket.onRead
注册的函数。 Titanium 桌面 API 还支持在套接字上添加和删除侦听器,但在接收数据时似乎没有一个侦听器起作用,只有内置的 onRead 函数。是否可以一次只听一个功能?
到目前为止我尝试过的:
1)创建一个全局函数,向其中添加侦听器,然后将其覆盖到每个模型。当我调用它时,覆盖方法似乎可以工作,但是当服务器发送数据时,它会发送到旧的非覆盖函数。
2) 将套接字变量复制到另一个变量并将侦听器附加到它,但这只是将侦听器附加到原始套接字变量。
3)尝试以我能想到的各种方式删除当前的监听功能。
任何帮助表示赞赏。谢谢
I am building a desktop application using Titanium Studio and a slightly modified version of corMVC(http://www.bennadel.com/projects/cormvc-jquery-framework.htm) to structure the app as model-view-controller. The problem i am having is with the socket listening function. What i am trying to do is to use the same function that listens to the incoming data in different models, but every time i add a new listening function in a different model like this: socket.onRead(readResponse);
it doesn't override the old function so when the server sends data to the client, it sends to all the functions registered with socket.onRead
. Titanium desktop API also supports add and remove listeners on the socket but none of the listeners seem to work when receiving data, just the built-in onRead function. Is it possible to only listen to one function at a time?
What i tried so far:
1) Making a global function add the listener to it, then override it to every model. The override method seems to work when i call it, but when the server sends data it sends to the old non-override function.
2) Copy the socket variable to another variable and attach the listener to it, but this just attaches the listener to the original socket variable.
3) Tried to remove the current listening function in every way i could think of.
Any help is appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论