ymofen / diocp-v5

delphi iocp, http, websocket, ntrip
BSD 2-Clause "Simplified" License
238 stars 110 forks source link

waiting for completion / synchroniuos call #4

Open pult opened 5 years ago

pult commented 5 years ago

create wsClient:

  DoInitializeWebSocketClient;

  var FWsClient: TDiocpWebSocketContext;

  FWsClient := NewWsClient();
  FWsClient.OnRecv := OnRecv;
  FWsClient.OnDisconnectedEvent := OnDisconnected;
  //FWsClient.OnShakeHand := OnShakeHand;
  FWsClient.Masked := True;

send data:

  var S: string;
  var lvBytes:TBytes;

  if not FWsClient.Active
  then FWsClient.Open('ws://localhost:3000/echo')
  else ? how CHECK FWsClient is in processed
         ? if FWsClient.Processed then exit
  ===========================================

  S := '{"method":"PingDevice","step":0}';
  lvBytes := StringToUtf8Bytes(S);
  FWsClient.SendBuffer(@lvBytes[0], Length(lvBytes), OPT_TEXT);

  ? how WAIT finally received data
  ? FWsClient.WaitingCompletion
  ================================
ymofen commented 5 years ago

TDiocpWebSocketContext 是异步的,如果需要知道什么时候发送完成, 可以在diocp的事件 FWsClient.OnSendBufferCompleted 中处理 如果SendBuffer发送成功,表示投递成功。