span8
span4
*** Note: The contents of this article have not been tested with FME Server 2016 or Newer. There is no further maintenance planned for the content or materials referenced in this article.
For the FME Server 2014 version of this article please see:WebSockets和FME服务器(2014)
本教程的代码和工作空间是在Github上托管。
WebSocket是一种相对较新的技术,在HTTP之上实现,允许基于双向浏览器的客户端 - 服务器通信,而没有轮询的开销(带有HTTP开销的AJAX请求),也不是客户端插件的不便和不可逼迫。现代浏览器包括用于连接到WebSockets服务器的JavaScript API的内置实现。
自2014年发布以来,FME服务器可以作为WebSocket服务器,无需额外的模块,允许与客户端Web应用程序快速实时通信,需要最小的设置。本教程将向您展示如何。
http://en.wikipedia.org/wiki/websocket.
http://www.html5rocks.com/en/tutorials/websockets/basics/
https://developer.mozilla.org/en/docs/WebSockets
有两种主要模式,其中WebSocket可以与FME服务器一起使用,您选择哪一个取决于您的应用程序。还可以将这些模式混合用于通信流的不同部分。
In all modes, a named stream is shared between clients. This means that FME Server can easily broadcast the same message to multiple clients, and receive communication from them on a single stream.
当您的通信低卷时使用此功能,或者如果您需要通知服务的灵活性。
In this case, communication between the engine (i.e. a running workspace) and the WebSocket server is routed through an FME Server topic by means of a WebSocket publisher and subscriber. Jobs are typically launched in response to a message on a topic, and complete when they have finished processing it.
当您具有大量消息时使用此功能,并仅处理浏览器 - 服务器通信。
在这种情况下,引擎(即运行工作区)直接连接到WebSocket服务器,并在取消作业之前继续运行。这确实符合一个发动机许可证,但删除启动发动机的开销并进行连接。
如果通信流的不同部分适合不同的描述,则可能希望将这些模式以组合模式混合。
在这种情况下,引擎将响应通知事件并直接在WebSocket上发送,或反之亦然。当没有许多请求时,这是有用的,但您仍然希望服务器在没有从客户端轮询的开销的情况下响应,或者您不想将连续运行的FME引擎专用于作业。
In this mode, FME Server integrates WebSocket-based communication into its existing notification framework.
In order to send and receive messages over WebSockets, we need to configure a Topic, a Publication and a Subscription, using the FME Server web interface. First, create a new topic called "topic_ws_sample."。Then create a new publication called "pub_ws_sample" with a stream ID "sample_stream_in."。下面是一个例子:
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), and the default port and path should be kept as-is. The WebSocket server will communicate on port 7078.
{ws_op:“打开”,ws_stream_id:“sample_stream_in”}这将在创建发布时指定的Stream ID上与FME服务器打开通信。
{ ws_op: "send", ws_msg: "FME Lizard reporting for duty." }
在FME服务器Web界面中,设置监视以查看传入消息。保持浏览器窗口打开,在FME桌面中运行工作区,您应该看到以下内容:
In this mode, the engine (i.e. running workspace) connects directly to the WebSocket server, and keeps running until you cancel the job.
{ "ws_topic":"disp_pnts" "ws_msg":"{\"lat\": \"49.1468009923073\", \"lon\": \"-122.672091674805\" }" }
需要WS_Topic和WS_MSG元素。WS_MSG可以包含您要发送的任何文本。
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.
前端网页包括Google地图接口和用于传入和传出消息的日志。它使两个WebSocket连接 - 一个用于发送用户选择的点,另一个用于接收位移点。访问Live演示
fmeserver.init({server:“http://: ”,令牌:“”
最后,我们将更改上述工作区以使用混合模式。
For a completed version, take a look at “displacer_modified.fmw” in the included files for this tutorial. As might be surmised, it is a modified version of displacer.fmw.
从“displacer.fmw”开始,尝试更改工作区,FME服务器设置和JavaScript代码以使用以下工作流程。亚搏在线您需要删除WebockEtreceiver,并将工作区订阅到主题。主题需要具有WebSocket发布。
The modified workspace should have a Text File Reader. You can specify “sample-json.json” as a data file, but it will be replaced by the incoming notification.
创建WebSocket发布。
访问http://
Congrats! You now know how to useHTML5 WebSockets和FME服务器- minimal overhead for communication between the browser and the server, and no server-side code required. Use WebSockets directly in消息流模式when you are dealing with a large volume of messages via WebSocket only. Couple WebSockets with FME Server’s Notification Service in通知模式when you want to send and receive using other protocols in addition to WebSockets. Or, combine the techniques inhybrid mode当您不想全职占用引擎时,但仍需要在一个方向上需要高吞吐量消息。
如果您不确定在Web应用程序中使用哪种模式,或者您对WebSockets和FME服务器有任何其他问题,请随时contact us。
© 2020 Safe Software Inc |Legal