# Not active anymore
Unfortunately I don't have time to support this project anymore. Also the websocket protocol has changed in the meantime, so it won't work with browser and other modern implementations.
Please take a look at the free (but closed) 3rd party component:
* http://www.esegece.com/websockets/download
* http://www.esegece.com/download/sgcWebSockets_free.zip
# DelphiWebsockets
Websockets and Socket.io for Delphi
See below for an event driven async example of an socket.io server and client:
```delphi
uses
IdWebsocketServer, IdHTTPWebsocketClient, superobject, IdSocketIOHandling;
var
server: TIdWebsocketServer;
client: TIdHTTPWebsocketClient;
const
C_CLIENT_EVENT = 'CLIENT_TO_SERVER_EVENT_TEST';
C_SERVER_EVENT = 'SERVER_TO_CLIENT_EVENT_TEST';
procedure ShowMessageInMainthread(const aMsg: string) ;
begin
TThread.Synchronize(nil,
procedure
begin
ShowMessage(aMsg);
end);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
server := TIdWebsocketServer.Create(Self);
server.DefaultPort := 12345;
server.SocketIO.OnEvent(C_CLIENT_EVENT,
procedure(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback)
begin
//show request (threadsafe)
ShowMessageInMainthread('REQUEST: ' + aArgument[0].AsJSon);
//send callback (only if specified!)
if aCallback <> nil then
aCallback.SendResponse( SO(['succes', True]).AsJSon );
end);
server.Active := True;
client := TIdHTTPWebsocketClient.Create(Self);
client.Port := 12345;
client.Host := 'localhost';
client.SocketIOCompatible := True;
client.SocketIO.OnEvent(C_SERVER_EVENT,
procedure(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback)
begin
ShowMessageInMainthread('Data PUSHED from server: ' + aArgument[0].AsJSon);
//server wants a response?
if aCallback <> nil then
aCallback.SendResponse('thank for the push!');
end);
client.Connect;
client.SocketIO.Emit(C_CLIENT_EVENT, SO([ 'request', 'some data']),
//provide callback
procedure(const ASocket: ISocketIOContext; const aJSON: ISuperObject; const aCallback: ISocketIOCallback)
begin
//show response (threadsafe)
ShowMessageInMainthread('RESPONSE: ' + aJSON.AsJSon);
end);
//start timer so server pushes (!) data to all clients
Timer1.Interval := 5 * 1000; //5s
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := false;
server.SocketIO.EmitEventToAll(C_SERVER_EVENT, SO(['data', 'pushed from server']),
procedure(const ASocket: ISocketIOContext; const aJSON: ISuperObject; const aCallback: ISocketIOCallback)
begin
//show response (threadsafe)
TThread.Synchronize(nil,
procedure
begin
ShowMessage('RESPONSE from a client: ' + aJSON.AsJSon);
end);
end);
end;
```
没有合适的资源?快使用搜索试试~ 我知道了~
Delphi的WebSocket客户端实现
共32个文件
pas:22个
dpr:2个
zip:1个
3星 · 超过75%的资源 需积分: 50 101 下载量 76 浏览量
2019-04-26
12:08:57
上传
评论 5
收藏 128KB RAR 举报
温馨提示
Delphi的WebSocket客户端实现 Delphi有免费的WebSocket客户端实现吗?我发现只有这一个: WebSockets Delphi Components
资源推荐
资源详情
资源评论
收起资源包目录
DelphiWebsockets-masterdemo.rar (32个子文件)
DelphiWebsockets-masterdemo
DelphiWebsockets-master
IdWebsocketServer.pas 6KB
ROdemoWS.zip 31KB
superobject
superobject.pas 174KB
superxmlparser.pas 39KB
IdServerWebsocketHandling.pas 13KB
uROHTTPWebsocketServer.pas 11KB
IdServerSocketIOHandling.pas 7KB
uROSimpleEventRepository.pas 4KB
uROIndyHTTPWebsocketChannel.pas 14KB
Demo
Unit1.dfm 791B
Unit1.pas 4KB
Project1.dpr 286B
uROIdServerWebsocketHandling.pas 2KB
IdServerIOHandlerWebsocket.pas 2KB
IdSocketIOHandling.pas 53KB
IdIOHandlerWebsocket.pas 42KB
IdServerBaseHandling.pas 105B
.gitignore 3KB
IdServerWebsocketContext.pas 3KB
README.md 3KB
wsdefines.pas 73B
DUnit
mtTestROWebSockets.pas 9KB
NewService_Impl.pas 2KB
Win32
Debug
html
wstest.html 1KB
NewLibrary_Intf.pas 4KB
UnitTestWebsockets.dpr 817B
UnitTestWebsockets.res 96B
mtTestWebSockets.pas 9KB
NewLibrary_Invk.pas 3KB
.gitattributes 483B
RemObjectsSDK_WS.js 9KB
IdHTTPWebsocketClient.pas 45KB
共 32 条
- 1
资源评论
- sczyq2021-11-20下载了,参考了一下,最后还是用 CEF 的 WebSocket 简单方便
liu494021458
- 粉丝: 5
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 修复windows系统库软件
- OpenCv 使用fffffffff
- 正点原子开拓者FPGA多人表决器代码项目
- EOP-Last5Years.txt
- windows 32位、64位系统常见缺少的库
- 毕业设计基于springboot+vue实现的求职招聘类型网站源码+数据库(高分项目).zip
- 535springboot + vue 体质测试数据分析及可视化设计.zip(可运行源码+数据库文件+文档)
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统源码.zip
- 基于springboot+vue实现的求职招聘类型网站源代码+数据库(优质毕设项目).zip
- iOS APP提审checklist
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功