I’m trying to connect to Dorico Pro 5.1.81 to use the Remote Control API. I’ve setup Scott Janssens Dorico.Net C# library in Visual Studio Code but it won’t connect to Dorico. I’m get the errors:
—> System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
—> System.Net.Http.HttpRequestException: Connection refused (localhost:4560)
I’ve also tried 127.0.0.1:4560 with the same result.
Is it my windows 11 setup? Dorico setup or something else that is preventing the connection?
Thanks derAbgang for the suggestion but it made no difference. Wouldn’t this only affect connections to an external system? I’m trying to make a connection entirely locally, i.e. both client and server are running on the same machine.
You can also check that Dorico is indeed listening on that port for connections. Try netstat -na | findstr /i "4560"
at a command prompt (as Administrator).
The Resource Monitor also has a “Listening Ports” section at the bottom of the Network tab.
I’m definitely out of my comfort zone with this stuff, but just wanted to confirm you followed all the instructions to complete the handshake first. Connect to ws://127.0.0.1:4560, then send the following:
After completing the handshake, it seems to work for me. I messed around with this a year or so ago, and never could figure out how to do the handshake with a Stream Deck. The Notation Express guys wrote a plugin to do it.
Can you post your code here? Also, have you tried compiling and running Program.cs example from the library?
What confuses me is that you are getting System.Net.WebSockets.WebSocketException and System.Net.Http.HttpRequestException.
ConnectAsync method from the library already catches those and throws internal DoricoException which wraps the original exception as InnerException. So why are you not getting a DoricoException with Could not connect to Dorico. Make sure Dorico is running. message?
Are you using the code from the sample project in the GitHub repo? If so, where are you getting the connection error? I have to switch to Dorico to allow the connection after line 36, and then I’m able to send other commands.
I am running the DoricoNetExample code in Program.cs in Visual Studio Code IDE. I’ve not yet created my own code to call the Dorico.Net.dll as wanted to investigate how it worked.
In the snippet that ikos posted, my error occurs on line 102
As I know that Dorico is running and that it is listening on the correct port (see previous posts), I wanted to know what the actual message was and this is shown in the Debug console of VSC
If you set the log level to Debug on line 16 in Program.cs, you should get the sent and received message at the comms level.
If you set the log level to Trace you should get the messages at the WebSocket level, although there’s a bug in the current NuGet package where the wrong value is sent to the logger. I just pushed a change to GitHub to fix that. Not sure when I’ll publish a new NuGet at this moment.
I suspect the connection is closed directly and not the result of a message.
Do you have the full stack trace from the exception? What you posted earlier doesn’t show the Dorico.net part of the code path. That might help yield some ideas. Although I suspect this is environmental.
------------------------------------------------------------------------------
You may only use the Microsoft Visual Studio .NET/C/C++ Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software to help you
develop and test your applications.
------------------------------------------------------------------------------
trce: DoricoRemote[1150959493]
Opening WebSocket: ws://127.0.0.1:4560/
trce: DoricoRemote[898765132]
WebSocket opened: ws://127.0.0.1:4560/
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
Exception thrown: 'DoricoNet.Exceptions.DoricoException' in Dorico.Net.dll
Exception thrown: 'DoricoNet.Exceptions.DoricoException' in System.Private.CoreLib.dll
Unhandled exception. DoricoNet.Exceptions.DoricoException: Could not connect to Dorico. Make sure Dorico is running.
---> System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
---> System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:4560)
---> System.Net.Sockets.SocketException (111): Connection refused
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.WebSockets.WebSocketHandle.ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken, ClientWebSocketOptions options)
at System.Net.WebSockets.WebSocketHandle.ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken, ClientWebSocketOptions options)
at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken)
at DoricoNet.Comms.DoricoCommsContext.ConnectAsync(IConnectionArguments connectionArgs) in /workspaces/Dorico.Net/Dorico.Net/Comms/DoricoCommsContext.cs:line 119
at DoricoNet.DoricoRemote.ConnectAsync(String clientName, IConnectionArguments connectionArguments) in /workspaces/Dorico.Net/Dorico.Net/DoricoRemote.cs:line 74
--- End of inner exception stack trace ---
at DoricoNet.DoricoRemote.ConnectAsync(String clientName, IConnectionArguments connectionArguments) in /workspaces/Dorico.Net/Dorico.Net/DoricoRemote.cs:line 102
at Program.<Main>$(String[] args) in /workspaces/Dorico.Net/DoricoNetExample/Program.cs:line 36
at Program.<Main>(String[] args)
The program '[49426] DoricoNetExample' has exited with code 0 (0x0).