尝试连接到Google云计算引擎spring websocket服务器的客户端正在关闭连接:立即达到1000。我在做什么错?
我正在Google云计算引擎实例上运行spring websocket / rest服务器。防火墙规则已正确配置,并且可以通过浏览器连接到VM,但是如果我尝试打开websocket连接,则会立即关闭。将websocket连接到我的本地计算机上的同一台服务器不会出现任何问题,并且http日志记录表明该服务器从不接收启动请求。 websocket客户端收到的连接已关闭:1000。这是websocket客户端代码:
`
void clientConnect(){
Serial.print("Sending connection to: ");
HTTPClient http;
http.begin(SERVER_ADDR);
int httpCode = http.GET();
if(httpCode > 0){
String parload = http.getString();
http.end();
int url = parload.indexOf("http");
int lastUrl = parload.lastIndexOf("\"");
String u = parload.substring(url + 4,lastUrl);
serverUrl = u;
}
Serial.println(serverUrl);
clnt.begin("35.247.188.177",80,"/network");
clnt.setReconnectInterval(RECONNECT_DELAY);
}
void gotEvent(WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED: {
Serial.printf("[WSc] Connected to url: %s\n", payload);
// send message to server when Connected
clnt.sendTXT("Connected");
}
break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload);
// send message to server
// webSocket.sendTXT("message here");
break;
case WStype_BIN:
Serial.printf("[WSc] get binary length: %u\n", length);
// send data to server
// webSocket.sendBIN(payload, length);
break;
case WStype_PING:
// pong will be send automatically
Serial.printf("[WSc] get ping\n");
break;
case WStype_PONG:
// answer to a ping we send
Serial.printf("[WSc] get pong\n");
break;
}
}
Websocket服务器配置:
@Configuration
@EnableWebSocket
public class WebSocketConfiguration implements WebSocketConfigurer {
private static Logger logger = LoggerFactory.getLogger(WebSocketConfiguration.class);
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
logger.info("Registering websocket handlers");
webSocketHandlerRegistry.addHandler(new DoorSocketConnectionHandler(),"/network").setAllowedOrigins("*");
}
}
客户端通过本地网络在我的本地计算机上连接没有问题,但是将服务器移至Google云计算引擎服务器后,它们立即被关闭。 HTTP日志显示服务器从未收到启动请求,并且spring / actuator / httptrace日志为空