Select to view content in your preferred language

Attempting to create a web socket to communicate between a Pro .NET Add-in and a JavaScript SDK web page

684
3
04-11-2023 08:48 AM
DaveLewis73
Regular Contributor

I am currently working on a project in ArcGIS Pro 3.1 using C# and the .NET SDK along with the JavaScript SDK to work out a way to "sync" my Pro map with a client web page that I have built using the JavaScript SDK.  With the guidance of the Esri team, I have been looking into using a web socket approach to perform this sync operation where the user would be navigating around in their Pro project and then be able to see that location in the web maps that are in the JavaScript web page (currently the web page has a 2D map view and a scene view). So, as the user zooms in/out or pans around and the JavaScript map views would be in sync and do the same.  Unfortunately, I have not been able to get the web socket to function properly where I simply need to send coordinates and scale to the JavaScript page.  I do not need to communicate back with the web socket server.  That being said, I am ultimately looking for how to build a very simple web socket server, access it and send coordinates and scale to it from my Pro Add-In, and finally have that information propagate down to the JavaScript web page.  Does anyone have any experience doing anything like this, or at least experience creating a simple socket web server and communicating with it?  Do I need to create a Windows service for the web socket server or do something entirely different?  I am rather lost at this point and would appreciate any insight/help on this subject.

0 Kudos
3 Replies
CharlesMacleod
Esri Regular Contributor

I suggest reading up on stream services: https://enterprise.arcgis.com/en/server/latest/publish-services/windows/stream-services.htm

That may be what u r after. Your stream service cld publish the extent of your map (in Pro) for example. 

 

 

0 Kudos
AlaindEspaignet
New Contributor

I did something similar a while back in a "collaborative map navigation" demo.

2 ESRI JS API map apps where users can take turns at showing each other things on a map.

Whereas there are many web sockets libraries out there you'll have the trouble of picking the right one for the C# and JS sides.

I took the easy route and used Ably.com. A few lines of code. Done.

They have a generous free tier.

PS: I am not affiliated to Ably. 

0 Kudos
DaveLewis73
Regular Contributor

I have thoroughly investigated Ably and it does appear that it may very well do what I am looking for.  Unfortunately, it is a paid service, which is not an option for me.  I need a freely available option.  So, as an update, I have currently tried two approaches and neither of them has worked for me thus far.  The first involved socket.io and node.js, which worked really well.  I was able to get my coordinates and zoom level from ArcGIS Pro and pass them off to a socket server, which in turn passed it off to the client.  However, I am not sure what the problem is, but it doesn't seem like the JavaScript SDK plays very well with socket.io and node.js.  When I tried to ingest the information from the server, I was only able to see the header of my JavaScript web map page.  It would not render anything else, including the map, and the rendering of the header was off as well.  Now, I have also tried working with TcpListener and TcpClient in C#.  However, I am unable to get that to work for me either.  Once again, I can send my information from ArcGIS Pro to a socket server, but in this case I am unable to pass the things on any further than the server.  The socket server receives, but it will not send to the JavaScript SDK web page.  As an fyi, in both cases, I am using two ports on localhost.  One port sends from Pro to the server and the second port should then send on to the web page.  Any thoughts?  Thank you!

0 Kudos