Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent connection error in console log for MCDU socket connection attempts #6939

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed debug messages
  • Loading branch information
frankkopp authored and svengcz committed Mar 19, 2022
commit 9a0fff26fdee3ae406eafd7516834a2fce381c7e
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ class A320_Neo_CDU_MainDisplay extends FMCMainDisplay {
// The MCDU is a client to the MCDU Server and tries to connect in regular intervals.
// every 2500ms
if (this.mcduServerConnectUpdateThrottler.canUpdate(_deltaTime) !== -1) {
if (this.socket) {
console.log("DEBUG: " + this.socket.readyState + "==================================");
}
if (!this.socket || this.socket.readyState !== 1) {
this.connectWebsocket(NXDataStore.get("CONFIG_EXTERNAL_MCDU_PORT", "8380"));
}
Expand Down Expand Up @@ -1430,25 +1427,18 @@ class A320_Neo_CDU_MainDisplay extends FMCMainDisplay {
* Attempts to connect to a local websocket server
*/
connectWebsocket(port) {
console.log('Socket1 = ' + this.socket);

if (this.socket) {
console.log('Socket1 ReadyState = ' + this.socket.readyState);
if (this.socket.readyState) {
Copy link
Member

@beheh beheh Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about readyState == 2 and == 3? Do we want to call socket.close when it's already CLOSING or CLOSED?

(Reference)

Copy link
Member Author

@frankkopp frankkopp Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already the case:

if (this.socket) {
    if (this.socket.readyState) { 
        console.log('Attempting to close socket: readyState=' + this.socket.readyState);
        this.socket.close();
    }
    delete this.socket;
}

All non 0 will be closed.
And the call during 3 does not cause an error message as my log above shows.

console.log('Attempting to close socket: readyState=' + this.socket.readyState);
this.socket.close();
}
delete this.socket;
}

console.log('Socket2 = ' + this.socket);

const url = `ws://127.0.0.1:${port}`;

this.socket = new WebSocket(url);

console.log('Socket3 = ' + this.socket);

this.socket.onerror = () => {
console.log(`WebSocket connection error. Maybe MCDU Server disconnected? (${url})`);
};
Expand Down