delphi 第三方控件 TsgcWebSocketClient使用

//在form上拖放一个TsgcWebSocketClient 控件,控件采用ws协议,代码如下
procedure TForm16.Button1Click(Sender: TObject);
begin
  try
    sgcWebSocketClient1.Host := 'echo.websocket.org';
    sgcWebSocketClient1.Port := 80;
    sgcWebSocketClient1.Active := True;
  except
    on E: Exception do
      ShowMessage(e.Message);
  end;
end;

//procedure TForm16.Button2Click(Sender: TObject);
//begin
//  sgcWebSocketServer1.Active := True;
//end;

procedure TForm16.Button3Click(Sender: TObject);
begin
  sgcWebSocketClient1.WriteData('{"data":"12345","name": "skdjfklaj"}');
end;

procedure TForm16.dealBackData(abc: string);
begin
  if Pos('name', abc) > 0 then
  begin
    ShowMessage('有!');
  end
  else
  begin
    ShowMessage('没有!');
  end;
end;

procedure TForm16.sgcWebSocketClient1Message(Connection: TsgcWSConnection; const Text: string);
begin
  Memo1.Lines.Add('Message Received From Server: ' + Text);
  dealBackData(Trim(Text));
end;

转载于:https://www.cnblogs.com/yangxuming/p/9253706.html

你可能感兴趣的:(网络)