kRPC: Control the game using C#, C++, Java, Lua, Python...

kRPC: Control the game using C#, C++, Java, Lua, Python...

7.8k Downloads

Websocket connection error

smartintruesdell opened this issue ยท 1 comments

commented

In working with a NodeJS Client here, I was following their getting started examples and found an issue where instantiating a new client was throwing an error instantiating the websocket connection:

error: Error: Parse Error: Expected HTTP/
at Socket.socketOnData (_http_client.js:509:22)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:307:12)
at readableAddChunk (_stream_readable.js:282:9)
at Socket.Readable.push (_stream_readable.js:221:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
bytesParsed: 0,
code: 'HPE_INVALID_CONSTANT',
reason: 'Expected HTTP/',

Running KSP_64 1.8.1 with krpc 0.4.8, a super simple test script in javascript hits this error 100% of the time:

const Websocket = require('ws');
new Websocket('ws://localhost:50000');

I tried grabbing a fresher build from the ci build s3 bucket but that didn't seem to improve the situation.

I fired up the python client and was able to connect and get telemetry from my craft, so it's definitely something between the server and Node's websocket/http client.

I dug into the error, and found this comment on a like error in the Node repository, saying that the problem is caused by malformed response to a HEAD request. Apparently HEAD requests aren't supposed to respond with data in the body.

They called this issue a 'wontfix', stating that the problem is on the server developer to follow standards and not with node's http or websocket clients to handle.

Does anyone have an intuitive sense for where the server is tripping up here?

commented

For anyone running into this in the future, you need to use the "EDIT" button on the KRPC interface in game to change from TCP to Websockets mode. After that, I was able to connect as expected.