Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Add WebSocket connection to StreamService #307

Open
AlexArcPy opened this issue Nov 11, 2016 · 6 comments
Open

Add WebSocket connection to StreamService #307

AlexArcPy opened this issue Nov 11, 2016 · 6 comments

Comments

@AlexArcPy
Copy link
Contributor

ArcRest

3.5.6

Enhancement

Shall we add support for the StreamService that comes with GeoEvent Extension? I've just added support StreamService now in the main repo, so we can get static properties. It would be really cool if one could connect to the service via the WebSocket and listen to events in Python. The REST page of Subscribe.

To connect with web sockets in Python, I used the websocket-client 0.37.0 package. Seems to be easy to use and stable. Below is a simple snippet for reading events from StreamService.

What's the best way to build in the websocket client so users don't need to install it themselves? Another thing is we are going to need to establish connection with ws://, so the current code will fail to run at the point of url type verification (it's not http/https).

I tested on a local simple StreamService and the code below worked fine.

Repo Steps or Enhancement details

from arcrest.ags.server import Server
from arcrest import AGSTokenSecurityHandler
from websocket import create_connection

ags_securityHandler = AGSTokenSecurityHandler(username='user',
                                              password='user',
                                              token_url=r'https://machine:6443/arcgis/tokens/')

url = r'https://machine:6443/arcgis/rest/services'
ags_service_obj = Server(url,ags_securityHandler)

ss = [s for s in ags_service_obj.services if
      s.url == r'https://machine:6443/arcgis/rest/services/Service_DEMO/StreamServer'][0]

ws = create_connection("wss://machine:6143/arcgis/ws/services/Service_DEMO/StreamServer/subscribe?token={0}".format(ags_securityHandler.token))

ws.next()

>>> gives the next event in JSON

@achapkowski
Copy link
Collaborator

@AlexArcPy I have not really looked at this, but do you think you could leverage the socket library?

https://docs.python.org/2.7/howto/sockets.html

@AlexArcPy
Copy link
Contributor Author

@achapkowski Andrew, let me check if socket module is capable of establishing web socket connection. Doesn't look as easy to work with as using websocket-client package.

@AlexArcPy
Copy link
Contributor Author

@achapkowski I have browsed around and it doesn't seem as as builtin module socket supports establishing connection via wss which is required to connect to a stream service. Do you think it's a bad idea to add some code that will depend on a 3rd party package? We could probably let users know that they need to install another package themselves?

@achapkowski
Copy link
Collaborator

@AlexArcPy I am not opposed to using 3rd party modules as long as the license allows for there use in this type of project.

@achapkowski
Copy link
Collaborator

@AlexArcPy use the 3rd party module.

@AlexArcPy
Copy link
Contributor Author

@achapkowski , thanks for getting back on this. I just didn't have time to respond to you; so this issue is paused on my site so far... sorry for that!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants