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.
对于FME Server的版本2014这篇文章,请参阅:的WebSockets和FME服务器(2014)
代码和本教程工作区是hosted on GitHub。
WebSockets的是一个相对较新的技术,在HTTP上实现的,即允许双向基于浏览器的客户端 - 服务器通信,无需轮询的开销(AJAX请求与HTTP开销),也没有不便和客户端插件的不可靠性。现代浏览器包括内置的一个JavaScript API的实现,用于连接到服务器的WebSockets。
自从2014年发布,FME Server可以充当无需额外模块的WebSocket服务器,允许快速与客户端的web应用程序的实时通信,需要最小的设置。本教程将告诉您如何。
http://en.wikipedia.org/wiki/WebSocket
http://www.html5rocks.com/en/tutorials/websockets/basics/
https://developer.mozilla.org/en/docs/WebSockets
有你选择哪一个将取决于你的应用程序中的WebSockets可以与FME Server一起使用两种主要模式,和。另外,也可以配合这些模式为所述通信流的不同部分。
在所有模式中,一个名为流客户端之间共享。这意味着FME服务器能够容易地广播相同的消息发送到多个客户端,并从它们在单个流接收的通信。
用这个当你交流是低容量,或 if you need the flexibility of the Notification Service.
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.
Use this when you have a high volume of messages, and are dealing with browser-server communication only.
In this case, the engine (i.e.running workspace) connects directly to the WebSocket server, and keeps running until you cancel the job.This does tie up one engine license, but removes the overhead of starting up an engine and making connections.
If different parts of your communication flow fit different descriptions, you may wish to blend these modes in a combined mode.
In this case, the engine will either respond to notification events and send directly on WebSocket, or vice-versa.This is useful when there aren’t many requests, but you still want the server to respond without the overhead of polling from the client, or you don’t want to dedicate a continuously running FME Engine to the job.
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"。See below for an example:
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 : "open", ws_stream_id : "sample_stream_in" }这将打开创建发布时指定的流ID与FME Server的通信。
{ ws_op: "send", ws_msg: "FME Lizard reporting for duty." }
In the FME Server Web Interface, set up Monitoring to view incoming messages.Keeping the browser window open, run the workspace in FME Desktop, and you should see the following:
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\" }" }
The ws_topic and ws_msg elements are required.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.
The front-end web page includes a Google Maps interface and logs for incoming and outgoing messages.It makes two WebSocket connections - one for sending the point the user selects, and the other for receiving the displaced point.Access Live Demo
FMEServer.init({ server : "http://: ", token : ""
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.As might be surmised, it is a modified version of displacer.fmw.
Starting with “displacer.fmw”, try changing the workspace, FME Server setup, and JavaScript code to use the following workflow.You’ll need to remove the WebSocketReceiver, and subscribe the workspace to a topic.The topic will need to have a WebSocket publication.
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.
创建 the WebSocket publication.
Visithttp://
Congrats!You now know how to useHTML5 WebSocketswithFME Server- minimal overhead for communication between the browser and the server, and no server-side code required.Use WebSockets directly inmessage streaming modewhen you are dealing with a large volume of messages via WebSocket only.Couple WebSockets with FME Server’s Notification Service innotification modewhen you want to send and receive using other protocols in addition to WebSockets.Or, combine the techniques inhybrid modewhen you don’t want to occupy an engine full-time, but still need high-throughput messaging in one direction.
If you’re not sure which mode to use in your web application, or you have any other questions about WebSockets and FME Server, feel free tocontact us。
©2020安全亚搏在线软件公司|法律