-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vahid
authored and
Vahid
committed
Sep 11, 2023
1 parent
fb3084e
commit 74a7aad
Showing
6 changed files
with
2,871 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Lazarus compiler-generated binaries (safe to delete) | ||
*.exe | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.lrs | ||
*.res | ||
*.compiled | ||
*.obj | ||
*.dbg | ||
*.ppu | ||
*.o | ||
*.or | ||
*.a | ||
|
||
# Lazarus autogenerated files (duplicated info) | ||
*.rst | ||
*.rsj | ||
*.lrt | ||
|
||
# Lazarus local files (user-specific info) | ||
*.lps | ||
|
||
# Lazarus backups and unit output folders. | ||
# These can be changed by user in Lazarus/project options. | ||
backup/ | ||
*.bak | ||
lib/ | ||
|
||
# Application bundle for Mac OS | ||
*.app/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CONFIG> | ||
<ProjectOptions> | ||
<Version Value="12"/> | ||
<General> | ||
<Flags> | ||
<MainUnitHasCreateFormStatements Value="False"/> | ||
<MainUnitHasTitleStatement Value="False"/> | ||
<MainUnitHasScaledStatement Value="False"/> | ||
</Flags> | ||
<SessionStorage Value="InProjectDir"/> | ||
<Title Value="WebSocketTest"/> | ||
<UseAppBundle Value="False"/> | ||
<ResourceType Value="res"/> | ||
</General> | ||
<BuildModes> | ||
<Item Name="Default" Default="True"/> | ||
</BuildModes> | ||
<PublishOptions> | ||
<Version Value="2"/> | ||
<UseFileFilters Value="True"/> | ||
</PublishOptions> | ||
<RunParams> | ||
<FormatVersion Value="2"/> | ||
</RunParams> | ||
<Units> | ||
<Unit> | ||
<Filename Value="WebSocketTest.lpr"/> | ||
<IsPartOfProject Value="True"/> | ||
</Unit> | ||
<Unit> | ||
<Filename Value="../../../Core/Synapse/blcksock.pas"/> | ||
<IsPartOfProject Value="True"/> | ||
</Unit> | ||
<Unit> | ||
<Filename Value="../WebSocket.Core.pas"/> | ||
<IsPartOfProject Value="True"/> | ||
</Unit> | ||
<Unit> | ||
<Filename Value="../WebSocket.Helper.pas"/> | ||
<IsPartOfProject Value="True"/> | ||
</Unit> | ||
</Units> | ||
</ProjectOptions> | ||
<CompilerOptions> | ||
<Version Value="11"/> | ||
<Target> | ||
<Filename Value="WebSocketTest"/> | ||
</Target> | ||
<SearchPaths> | ||
<IncludeFiles Value="$(ProjOutDir)"/> | ||
<OtherUnitFiles Value="../../../Core/Synapse;.."/> | ||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> | ||
</SearchPaths> | ||
<Linking> | ||
<Debugging> | ||
<DebugInfoType Value="dsDwarf2Set"/> | ||
</Debugging> | ||
</Linking> | ||
</CompilerOptions> | ||
<Debugging> | ||
<Exceptions> | ||
<Item> | ||
<Name Value="EAbort"/> | ||
</Item> | ||
<Item> | ||
<Name Value="ECodetoolError"/> | ||
</Item> | ||
<Item> | ||
<Name Value="EFOpenError"/> | ||
</Item> | ||
</Exceptions> | ||
</Debugging> | ||
</CONFIG> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
program WebSocketTest; | ||
|
||
{$Mode Delphi} | ||
|
||
uses | ||
cthreads, | ||
Classes, | ||
SysUtils, | ||
WebSocket.Helper, | ||
WebSocket.Core; | ||
|
||
type | ||
TMyClass = class | ||
public | ||
procedure OnRead(Sender: TWebSocketCustomConnection; {%H-}Flags: TWSFlags; OpCode: Byte; Data: TMemoryStream); | ||
procedure OnReadFull(Sender: TWebSocketCustomConnection; OpCode: Byte; Data: TMemoryStream); | ||
procedure OnPing(Sender: TWebSocketCustomConnection; Data: AnsiString); | ||
procedure OnPong(Sender: TWebSocketCustomConnection; Data: AnsiString); | ||
end; | ||
|
||
{ TMyClass } | ||
|
||
procedure TMyClass.OnRead(Sender: TWebSocketCustomConnection; Flags: TWSFlags; OpCode: Byte; Data: TMemoryStream); | ||
var | ||
s: AnsiString; | ||
begin | ||
SetLength(s{%H-}, Data.Size); | ||
Move(Data.Memory^, s[1], Data.Size); | ||
WriteLn(OpCode, ':', Data.Size, '-', s); | ||
end; | ||
|
||
procedure TMyClass.OnReadFull(Sender: TWebSocketCustomConnection; OpCode: Byte; Data: TMemoryStream); | ||
begin | ||
WriteLn(OpCode, ':', Data.Size, '-', PAnsiChar(Data.Memory)); | ||
end; | ||
|
||
procedure TMyClass.OnPing(Sender: TWebSocketCustomConnection; Data: AnsiString); | ||
begin | ||
WriteLn('PING:', Length(Data), '-', Data); | ||
end; | ||
|
||
procedure TMyClass.OnPong(Sender: TWebSocketCustomConnection; Data: AnsiString); | ||
begin | ||
WriteLn('PONG:', Length(Data), '-', Data); | ||
end; | ||
|
||
var | ||
Client: TWebSocketClient; | ||
MyClass: TMyClass; | ||
i: Integer; | ||
|
||
begin | ||
MyClass := TMyClass.Create; | ||
Client := TWebSocketClient.CreateFromURL('wss://127.0.0.1/websocket/test'); | ||
Client.OnRead := MyClass.OnRead; | ||
Client.OnReadFull := MyClass.OnReadFull; | ||
Client.OnPing := MyClass.OnPing; | ||
Client.OnPong := MyClass.OnPong; | ||
Client.Start; | ||
Client.WaitForConnect(10000); | ||
Client.SendText('HeloHeloHeloHelo'); | ||
Client.SendText('Hello', []); | ||
Client.SendTextContinuation('Hello', []); | ||
Client.SendTextContinuation('Hello', []); | ||
Client.SendTextContinuation('Hello', [FIN]); | ||
Client.Ping('PingPingPing'); | ||
for i := 1 to 10 do begin | ||
Client.SendText('Hello ' + IntToStr(i)); | ||
Client.Ping('Ping ' + IntToStr(i)); | ||
Sleep(1000); | ||
end; | ||
Readln; | ||
Client.Ping('PingPingPing'); | ||
Client.Free; | ||
MyClass.Free; | ||
Writeln('FINISHED!'); | ||
end. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# libWebSocket.pas | ||
|
||
### WebSocket server/client implementation in Object Pascal | ||
|
||
This project is based directly on pure Pascal source code. | ||
|
||
Project contains implementation of clients and servers using WebSocket protocol RFC (http://tools.ietf.org/html/rfc6455) | ||
|
||
This library is a remastered, rewritten and customized version of | ||
https://github.com/MFernstrom/Bauglir-WebSocket-2 | ||
and | ||
https://github.com/Robert-112/Bauglir-WebSocket-2 | ||
which originally are based on Bronislav Klucka source code as | ||
http://code.google.com/p/bauglir-websocket | ||
This library requirements Ararat Synapse (http://www.ararat.cz/synapse/) socket library to compile. | ||
|
Oops, something went wrong.