DelphiWebsockets-master

所属分类:Pascal/Delphi编程
开发工具:Delphi
文件大小:133KB
下载次数:6
上传日期:2020-07-08 03:56:21
上 传 者Bog_OGna
说明:  Delphi websocket demo.

文件列表:
DUnit (0, 2018-01-05)
DUnit\NewLibrary_Intf.pas (4206, 2018-01-05)
DUnit\NewLibrary_Invk.pas (3142, 2018-01-05)
DUnit\NewService_Impl.pas (2485, 2018-01-05)
DUnit\UnitTestWebsockets.dpr (817, 2018-01-05)
DUnit\UnitTestWebsockets.res (96, 2018-01-05)
DUnit\Win32 (0, 2018-01-05)
DUnit\Win32\Debug (0, 2018-01-05)
DUnit\Win32\Debug\html (0, 2018-01-05)
DUnit\Win32\Debug\html\wstest.html (1313, 2018-01-05)
DUnit\mtTestROWebSockets.pas (8932, 2018-01-05)
DUnit\mtTestWebSockets.pas (9392, 2018-01-05)
Demo (0, 2018-01-05)
Demo\Project1.dpr (286, 2018-01-05)
Demo\Unit1.dfm (791, 2018-01-05)
Demo\Unit1.pas (4133, 2018-01-05)
IdHTTPWebsocketClient.pas (46297, 2018-01-05)
IdIOHandlerWebsocket.pas (43106, 2018-01-05)
IdServerBaseHandling.pas (105, 2018-01-05)
IdServerIOHandlerWebsocket.pas (2047, 2018-01-05)
IdServerSocketIOHandling.pas (6805, 2018-01-05)
IdServerWebsocketContext.pas (2913, 2018-01-05)
IdServerWebsocketHandling.pas (12869, 2018-01-05)
IdSocketIOHandling.pas (54526, 2018-01-05)
IdWebsocketServer.pas (6152, 2018-01-05)
ROdemoWS.zip (32189, 2018-01-05)
RemObjectsSDK_WS.js (8823, 2018-01-05)
superobject (0, 2018-01-05)
superobject\superobject.pas (178125, 2018-01-05)
superobject\superxmlparser.pas (40209, 2018-01-05)
uROHTTPWebsocketServer.pas (11309, 2018-01-05)
uROIdServerWebsocketHandling.pas (2548, 2018-01-05)
uROIndyHTTPWebsocketChannel.pas (14190, 2018-01-05)
uROSimpleEventRepository.pas (4237, 2018-01-05)
wsdefines.pas (73, 2018-01-05)

# 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; ```

近期下载者

相关文件


收藏者