Android device link speed is slow
chenqinggang001 opened this issue · comments
I found that the cause of the problem was the use of this callback, it was very slow on some devices, I commented out this part of the code and the link speed was normal
@Override
public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(WebSocket conn, Draft draft, ClientHandshake request) throws InvalidDataException {
ServerHandshakeBuilder builder = super.onWebsocketHandshakeReceivedAsServer( conn, draft, request );
Log.d("zb", "WebSocketServer onWebsocketHandshakeReceivedAsServer: " + conn.getLocalSocketAddress() + " " + conn.getRemoteSocketAddress());
if (Objects.equals(conn.getLocalSocketAddress().getHostName(), conn.getRemoteSocketAddress().getHostName())) {
// 判断是否是自己,拒绝自己连接,减少广播数据消耗
throw new InvalidDataException(CloseFrame.POLICY_VALIDATION, "Not accepted!");
}
return builder;
}
I think that code actually does two DNS lookups, which would certainly make it slow. Look at the documentation for getHostname()
.
I removed the getHostName method and replaced it with getAddress, and the problem disappeared