斯潘8
span4
***注:本文内容未经FME Server 2016或更新版本测试。本文中引用的内容或材料没有进一步的维护计划。
For the FME Server 2014 version of this article please see:WebSockets and FME Server (2014)
Code and workspaces for this tutorial are在Github上托管.
WebSockets are a relatively new technology,在HTTP之上实现,它允许基于浏览器的客户端-服务器双向通信,而不需要轮询开销(具有HTTP开销的Ajax请求)。nor the inconvenience and unreliability of client plugins.Modern browsers include built-in implementations of a JavaScript API for connecting to a WebSockets server.
自2014年发布以来,FME服务器可以作为WebSocket服务器而不需要额外的模块,允许与客户端Web应用程序进行快速实时通信,需要最少的设置。This tutorial will show you how.
http://en.wikipedia.org/wiki/WebSocket
http://www.html5rocks.com/en/tutorials/websockets/basics/
https://developer.mozilla.org/en/docs/WebSockets
There are two main patterns in which WebSockets can be used with FME Server,and which one you choose will depend upon your application.还可以为通信流的不同部分混合这些模式。
在所有模式下,命名流在客户端之间共享。这意味着FME服务器可以轻松地向多个客户机广播相同的消息,并在一条流上接收他们的通信。
当你的通讯音量很低时使用这个,or if you need the flexibility of the Notification Service.
在这种情况下,communication between the engine (i.e.运行的工作区)和WebSocket服务器通过WebSocket发布者和订阅者通过FME服务器主题进行路由。作业通常是响应主题上的消息而启动的,并在完成处理后完成。
Use this when you have a high volume of messages,and are dealing with browser-server communication only.
在这种情况下,发动机(即运行工作区)直接连接到WebSocket服务器,and keeps running until you cancel the job.This does tie up one engine license,但它消除了启动引擎和建立连接的开销。
If different parts of your communication flow fit different descriptions,您可能希望以组合模式混合这些模式。
在这种情况下,引擎将响应通知事件并直接在WebSocket上发送,反之亦然。当请求不多时,这很有用,但是您仍然希望服务器响应而不需要来自客户机的轮询开销,or you don't want to dedicate a continuously running FME Engine to the job.
在这种模式下,FME服务器将基于WebSocket的通信集成到其现有的通知框架中。
为了通过WebSockets发送和接收消息,我们需要配置一个主题,a Publication and a Subscription,使用FME服务器Web界面。第一,创建一个名为“的新主题”topic_ws_sample".Then create a new publication called "蛹状样品“具有流ID”样品流入".请参见下面的示例:
Note that the target URL should have the publicly accessible host name of the FME Server machine (the URL is configured to use localhost by default),默认的端口和路径应该保持原样。WebSocket服务器将在端口7078上通信。
{ ws_op : "open",ws_stream_id:“sample_stream_in”This opens the communication with FME Server on the stream id specified when creating the publication.
{ ws_op: "send",ws_msg: "FME Lizard reporting for duty." }
在FME服务器Web界面中,set up Monitoring to view incoming messages.Keeping the browser window open,在FME桌面上运行工作区,您应该看到以下内容:
在这种模式下,发动机(即运行工作区)直接连接到WebSocket服务器,and keeps running until you cancel the job.
“ws_topic”:“disp_pnts”“ws_msg”:“\”lat\“:\”49.146809923073\“,\“隆\”:\“-122.672091674805 \”“”
需要ws_topic和ws_msg元素。ws_msg can contain any text you wish to send.
In the www folder of the tutorial files,"index.html" has all the JavaScript code needed to interface with FME Server in the web browser via web sockets.
前端网页包括一个谷歌地图界面,以及接收和发送信息的日志。它有两个WebSocket连接-一个用于发送用户选择的点,and the other for receiving the displaced point.Access Live Demo
fmeserver.init(服务器:“http:///: “令牌:“
Finally,we will change the above workspace to use hybrid mode.
For a completed version,take a look at "displacer_modified.fmw" in the included files for this tutorial.可以推测的是,它是置换器.fmw的改进版本。
从“置换器.fmw”开始,尝试更改工作区,FME Server setup,and JavaScript code to use the following 亚搏在线workflow.您需要删除WebSocketReceiver,and subscribe the workspace to a topic.主题需要有一个WebSocket发布。
修改后的工作区应具有文本文件读取器。You can specify "sample-json.json" as a data file,但它将被传入的通知替换。
Create the WebSocket publication.
Visithttp://
恭喜!你现在知道怎么用了HTML5网络插座具有FME服务器-浏览器和服务器之间的通信开销最小,and no server-side code required.直接在中使用WebSocketsmessage streaming modewhen you are dealing with a large volume of messages via WebSocket only.在中将WebSockets与FME服务器的通知服务耦合通知模式when you want to send and receive using other protocols in addition to WebSockets.Or,combine the techniques in混合模式当你不想占用一台发动机的全部时间时,但仍然需要单向的高吞吐量消息传递。
如果您不确定要在Web应用程序中使用哪种模式,或者您对WebSockets和FME服务器还有其他问题,随意联系我们.
© 2019 亚搏在线Safe Software Inc |合法的