我正在使用混合连接从侦听器请求数据。如果我可以读写连接,我怎么知道我从连接中读取的响应与我给它的请求相匹配?例如:
private HybridConnectionClient _client = new HybridConnectionClient(***);
public override async Task<RelayResponse> SendAsync(RelayRequest request)
{
var stream = await _client.CreateConnectionAsync();
var writer = new StreamWriter(stream) { AutoFlush = true };
var reader = new StreamReader(stream);
var reqestSerialized = JsonConvert.SerializeObject(request);
await writer.WriteLineAsync(reqestSerialized);
string responseSerialized = await reader.ReadLineAsync();
var response = JsonConvert.DeserializeObject<RelayResponse>(responseSerialized);
return response;
}
如果此连接上的侦听器同时读取和响应多个请求,是否知道我们在客户端执行的下一个 Readline() 以获取响应是与请求相关联的那个?或者这是必须管理的东西?