码迷,mamicode.com
首页 > Web开发 > 详细

TWebSocketClient

时间:2019-02-14 15:19:06      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:pre   var   phi   span   picker   and   通讯协议   creat   listbox   

TWebSocketClient

支持WEBSOCKET通讯协议的客户端控件。

连接WEBSOCKET SERVER的代码演示:

WebSocketClient1.HostName := ‘88.198.69.227‘;
WebSocketClient1.Port := 8888;

WebSocketClient1.Disconnect;

WebSocketClient1.Connect;

接收数据事件:

procedure TForm43.WebSocketClient1DataReceived(Sender: TObject; Origin: string;
  Data: TJSObject);
var
  it: TTMSFNCListBoxItem;
  sl: TStringList;
  s: String;
  n: string;
  v: string;
begin
  lst.BeginUpdate;
  it := lst.Items.Add;
  s := Data.toString;
  sl := TStringList.Create;
  try
    TTMSFNCUtils.Split(~, s, sl);
    if sl.Count > 2 then
    begin
      n := <font color="+sl[0]+" size="16">+sl[1];
      v := sl[2];
      it.Text := n +  says: </font><font size="16"> + v+</font>;
    end;
  finally
    sl.Free;
  end;
  lst.EndUpdate;
end;

 发送数据演示:

procedure TForm43.SendMessage;
var
  s: string;
begin
  if FConnected and (WebEdit2.Text <> ‘‘) then
  begin
    s := TTMSFNCGraphics.ColorToHTML(TMSFNCColorPicker1.SelectedColor) + ‘~‘ + WebEdit1.Text + ‘~‘ + WebEdit2.Text;
    // limit message length
    s := Copy(s,1,256);
    WebSocketClient1.Send(s);
    WebEdit2.Text := ‘‘;
  end;
end;

  

TWebSocketClient

标签:pre   var   phi   span   picker   and   通讯协议   creat   listbox   

原文地址:https://www.cnblogs.com/hnxxcxg/p/10374594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!