failed: Error during WebSocket handshake: Unexpected response code: 404

I updated server from 2017 R2 to 2019 R1.

and tried to open my web app. my web app uses mobile SDK and show camera-views on page.

But I got following error.

XPMobileSDK.library.js:2739 WebSocket connection to ‘ws://192.168.1.125:9003/adaptor/connection/XProtectMobile/Video/534be663-d505-41a6-937c-d802cc788e01/’ failed: Error during WebSocket handshake: Unexpected response code: 404

what would be issue?

Hello Lee,

just a clarification question: did you update the XPMobileSKD in your app as well ?

No, I didn’t because I couldn’t get SDK for the version. where is it ?

And the current SDK looks working well, but only websocket issue.

There is way to update SDK easily? My source code is very complicated. the SDK will be same format with old version?

will not need to change anything?

the following files are XPMobileSDK.js and XPMobileSDK.library.js, and I used them in my code(milestone.js). there are working on old version. but not working on 2019 R1 version.

I hope this help you. I’d like to work new SDK with my file(milestone.js)

XPMobileSDK.js

XPMobileSDK.library.js

milestone.js

When you install the new Mobile server there will be a folder were our Web client is located. Usually it is here : [C:\Program](file:C:/Program) Files\Milestone\XProtect Mobile Server\Web

In this folder there will be one named XPMobileSDK, here you can find the SDK and the samples. It should be backwards compatible, so only copy/paste should be ok. But please make a backup before you do any changes to your app.

You can test some of the samples in the SDK to see if they are working (https://doc.developer.milestonesys.com/mipsdkmobile/samples/HostOnServer_5.html). If this is the case then you can compare what is the difference between your app and the sample app.

I hope that helps.

Hi Lee,

Is your app hosted in the Mobile server or on another one ?

Because in the second case there could be something with CSP or CORS. I think they both have been updated, including special handling for the WebSockets between described server versions.

If that is the case, you could sniff the low level communication (from the browser or via external tool like wireshark) and check the values of the “Content-Security-Policy” and “Access-Control-Allow-Origin” settings in the Mobile server configuration file.

Hello Teodor, I’m working with Lee Bin (who started this thread).

We have two Milestone servers:

(1) one older Milestone Husky M30 Professional 2017 R1 server.

(2) new Milestone Husky X2 Professional (non plus) 2019 R1 server.

Our web-page works with the Professional 2017 R1 server.

But we get the following error with the Professional (non plus) 2019 R1 server (when trying to view cameras):

XPMobileSDK.library.js:2739 WebSocket connection to ‘ws://192.168.1.125:9003/adaptor/connection/XProtectMobile/Video/534be663-d505-41a6-937c-d802cc788e01/’ failed: Error during WebSocket handshake: Unexpected response code: 404

Perhaps we need a newer XPMobielSDK.library.js library that will work with Milestone Professional 2019 R1 ?

IF so, where could be obtain that XPMobielSDK.library.js ?

Are there known incompatibilities between the XPMobielSDK.library.js obtained in 2017 with Professional 2017 R1, and the Professional 2019 R1 we are trying to use now?

We purchased Express+ Care Premium Base License, Care Premium Device License, and Care Plus for Camera License (3-Yrs), but we are currently using an older version 1-Yr TEST License (for Professional (non plus) 2018 R1, because newer and +plus versions do not have the Central API).

Thank you!

Hi Daniel, please check my latest post to find out where is the XPMobielSDK.library.js . Also check the Peter Vutov comment I think it is relevant.

could you please answer my questions below?

I updated CSP and CORS in VideoOS.MobileServer.Service.exe.config and restarted mobile server. but it showed same error.

/XProtectMobile/Video/534be663-d505-41a6-937c-d802cc788e01/

This url format is available on new server ?

what did you change in new SDK files? the changes are related to this url ?

maybe you know what issue is related to.

Also, I checked mobile server logs. there are some errors

2020-11-06;9:07:07 PM;Error;HttpListenerAsync.ListenerCallback;The I/O operation has been aborted because of either a thread exit or an application request
 
2020-11-06;9:07:08 PM;Info;DataChannelsManager.OnDataChannelClose();Stream Closed Without Request! StreamID: 05ad37d4-9588-4843-8dc7-b89e22cedef1, CommChannelID: cbc86158-d054-47c2-9a7a-444a866160ca
 
2020-11-06;9:08:59 PM;Info;MipSdkWrapper.CheckSettings();Number of read configurations: 1
2020-11-06;9:08:59 PM;Info;MipSdkWrapper.GetConfigurationByServerId();Settings has been found.
2020-11-06;9:08:59 PM;Info;Main thread;Current Culture: en-US
2020-11-06;9:08:59 PM;Info;Main thread;Current UI Culture: en-US
2020-11-06;9:08:59 PM;Info;AlarmSecurityManager.TryRefreshUsers;All users list updated.
2020-11-06;9:08:59 PM;Error;RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.

And I saw similar articles here, But nothing is helpful.

https://developer.milestonesys.com/s/article/cannot-view-playback-web-and-mobile-client-troubleshooting

https://developer.milestonesys.com/s/question/0D53X00005tpCnCSAU/not-able-to-connect-to-milestone-mobile-server-over-https

and I was going to update XPMobileSDK.js and XPMobileSDK.library.js, but they were changed much and hard to integrate with my React app. I think they should be easy to use. Could you look the files I attached? the files are what I used in my app.

I tried to update new SDK (I thought I replace new files simply), but you changed the format much.

Could you look and advise me ? Maybe you can compare them with my old SDK files and correct in the format?

I appreciate your help

when I used new SDK, show this error.

TypeError: Cannot read property 'src' of null
initialize
C:/MERN-securitySafetySystem/CMSS/src/ducks/XPMobileSDK.js:143
  140 | 
  141 | var script = document.querySelector('script[src$="' + XPMobileSDKSettings.fileName + '"]');
  142 | 
> 143 | path = script.src.replace(RegExp(XPMobileSDKSettings.fileName + '.*$'), '');
  144 | head = document.querySelector('head');
  145 | 
  146 | load(XPMobileSDKSettings.includes.slice());

The general format of the Video URLs hasn’t been changed. Server log doesn’t show anything special (well except the underlying TCP connection was closed ).

I’m not sure I understand what you aim to do with this initialization JS code.

btw I didn’t understand what are your settings in the MoS config file about CSP and CORS as well as where is your application hosted and how you load the JS SDK.

Hi Petar

you said you didn’t understand my js files, that’s what I customized your SDK files in order to use those in my react app. That’s how hard your SDK is to use.

the SDK files should be easy to use. but whenever you change SDK, I had to analyze entire code and customize. also, variable and function names doesn’t make sense.

I just confirmed the problem is in server. when I put old server url, the url was working, But when I put new server url, the url appeared as “404” with socket handshake error. If the format of video URLs was not changed, why it shows these errors when I changed server url only ?

I see many errors in mobile server log

Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:47 AM;Error;RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:47 AM;Error;RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:48 AM;Error;RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:48 AM;Error;RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:48 AM;Error;RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:48 AM;Error;RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:48 AM;Info;LicenseWrapper;OnlineExpiration is False
2020-11-09;10:10:48 AM;Info;LicenseWrapper;OnlineExpiration is False
2020-11-09;10:10:51 AM;Error;DeviceScanner.RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:51 AM;Error;DeviceScanner.RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:51 AM;Error;DeviceScanner.RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:51 AM;Error;DeviceScanner.RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:51 AM;Error;DeviceScanner.RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:51 AM;Error;DeviceScanner.RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
2020-11-09;10:10:51 AM;Error;DeviceScanner.RequestCallback;Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.

what is this error?

please check the logs and advise solution

I’ll repeat the question for the third time:

I didn’t understand what are your settings in the MoS config file about CSP and CORS as well as where is your application hosted and how you load the JS SDK.

You haven’t made also a wireshark trace of the communication during websocket establishment.

yes. I mentioned the old version is working well. That means I did config file as well. and it is React app.

what did you change for the part in new server ?

and regarding of config file, all are same with old server, and I changed VideoOS.MobileServer.Service.exe.config file in new server as well.

Hello Lee,

I checked the milestone.js file and what is there is how to connect and login to the Mobile server. This does not show how you request a stream and how you are building the video channel where the data will be retrieved.

Also XPMobileSDK is not compatible with any framework but only for native JavaScript. We understand that people would like an integration to the most popular frameworks but they are so many that we can not support them all.

Please share with us how do you access ws://192.168.1.125:9003/adaptor/connection/XProtectMobile/Video/534be663-d505-41a6-937c-d802cc788e01/

. The adaptor/connection is not something that we support so there should be some routing or proxy between the your implementation and the Mobile server

Thank you for your understanding.

yes. it should be native javascript, but it should be easy to use in other framework as well.

I will show code for the adaptor part.

this is the code to communicate with SDK.

download adaptor code example

As I mentioned, the old version works well.

Please advise me.

Hello Lee,

I went through the implementation and I didn’t find any problem. Can you please do a Wireshark trace of the communication and attach it so that we can check what is the data flow between your application and the Mobile server.

Hello Teodor,

We are trying your suggestion to do a Wireshark trace.

There was a tropical storm (ETA), so our network was down a while.

We’ll get back soon with the Wireshark trace results.

Hi Teodor

I am not sure if this would help.

This is all I got related to SDK.

Download log file

Hi Lee,

unfortunately does not help much as it doesn’t contain the detailed information. In order to progress here we would really need a trace from https://www.wireshark.org software. It is free just install it where the client is located and start logging the traffic. Then export the log file and send it yo us.