@OverridepublicConnectionconnectToServer(ServerInfoserverInfo){try{if(grpcExecutor==null){this.grpcExecutor=createGrpcExecutor(serverInfo.getServerIp());}//这里就是计算端口的逻辑,serverPort默认为8848,rpcPortOffset为1000intport=serverInfo.getServerPort()+rpcPortOffset();ManagedChannelmanagedChannel=createNewManagedChannel(serverInfo.getServerIp(),port);//新建RequestGrpc.RequestFutureStubnewChannelStubTemp=createNewChannelStub(managedChannel);if(newChannelStubTemp!=null){Responseresponse=serverCheck(serverInfo.getServerIp(),port,newChannelStubTemp);if(response==null||!(responseinstanceofServerCheckResponse)){shuntDownChannel(managedChannel);returnnull;}BiRequestStreamGrpc.BiRequestStreamStubbiRequestStreamStub=BiRequestStreamGrpc.newStub(newChannelStubTemp.getChannel());GrpcConnectiongrpcConn=newGrpcConnection(serverInfo,grpcExecutor);grpcConn.setConnectionId(((ServerCheckResponse)response).getConnectionId());//createstreamrequestandbindconnectioneventtothisconnection.StreamObserver<Payload>payloadStreamObserver=bindRequestStream(biRequestStreamStub,grpcConn);//streamobservertosendresponsetoservergrpcConn.setPayloadStreamObserver(payloadStreamObserver);grpcConn.setGrpcFutureServiceStub(newChannelStubTemp);grpcConn.setChannel(managedChannel);//sendasetuprequest.ConnectionSetupRequestconSetupRequest=newConnectionSetupRequest();conSetupRequest.setClientVersion(VersionUtils.getFullClientVersion());conSetupRequest.setLabels(super.getLabels());conSetupRequest.setAbilities(super.clientAbilities);conSetupRequest.setTenant(super.getTenant());grpcConn.sendRequest(conSetupRequest);//waittoregisterconnectionsetupThread.sleep(100L);returngrpcConn;}returnnull;}catch(Exceptione){LOGGER.error("[{}]Fail to connect to server!,error={}",GrpcClient.this.getName(),e);}returnnull;}